在最近做的项目中有碰到要写类似朋友圈的模块,因为要实现评论点赞功能,这里说下我是怎么实现评论功能的。
首先先放上效果图
这里贴上我的代码:
//给评论图标设置点击事件
mIv_header_discuss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPopupcomment();
}
});
showPopupcomment()方法如下
private PopupWindow popupWindow;
private View popupView = null;
private EditText inputComment;
private String nInputContentText;
private TextView btn_submit;
private RelativeLayout rl_input_container;
private InputMethodManager mInputManager;
@SuppressLint("WrongConstant")
private void showPopupcomment() {
if (popupView == null){
//加载评论框的资源文件
popupView = LayoutInflater.from(context).inflate(R.layout.comment_popupwindow, null);
}
inputComment = (EditText) popupView.findViewById(R.id.et_discuss);
btn_submit = (Button) popupView.findViewById(R.id.btn_confirm);
rl_input_container = (RelativeLayout)popupView.findViewById(R.id.rl_input_container);
//利用Timer这个Api设置延迟显示软键盘,这里时间为200毫秒
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run()
{
mInputManage