需求实现:点击用户评论列表项,弹出输入法并进行编辑回复功能
来源:互联网 发布:唯美现代诗 知乎 编辑:程序博客网 时间:2024/06/10 18:06
工作日志记录:在项目开发的过程中,碰到一个需求就是在你点击用户回复列表的某一项的时候需要实现弹出输入法并输入评论然后发送评论内容的功能,现在将实现过程记录下来。
实现效果图:
上面左边是评论列表图,右边是输入法弹出的图。
实现思路:由于左图中是没有看见文本编辑框和发送按钮的,所以我需要将这连个控件放在底部并以不可见的状态存在于底部,当点击条目是,将这两个控件的状态置为可见,获取焦点并弹出输入法。
实现代码如下:
//监听软键盘是否显示或隐藏,用于判断什么时候隐藏这个edittext和发送按钮 ll_inputmethod.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect r = new Rect(); ll_inputmethod.getWindowVisibleDisplayFrame(r); int screenHeight = ll_inputmethod.getRootView() .getHeight(); int heightDifference = screenHeight - (r.bottom);// Toast.makeText(activity, "heightDiff"+heightDifference, Toast.LENGTH_SHORT).show(); if (heightDifference > 200) { //软键盘显示 ll_inputmethod.setVisibility(View.VISIBLE); } else { //软键盘隐藏 ll_inputmethod.setVisibility(View.GONE); } edit_comment.setText("");//初始化操作 } });
/** * EditText获取焦点并显示软键盘 */ public void showSoftInputFromWindow(Activity activity, EditText editText,boolean hideOrNot) { editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus();// activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); //打开软键盘 InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); if(hideOrNot){ imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); }else{ imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }
发送按钮的点击事件:
case R.id.tv_send: String comment=edit_comment.getText().toString().trim(); if(!TextUtils.isEmpty(comment)) { if(commentId!=-1) { //评论他人的评论 }else{ //评论该文章 } showSoftInputFromWindow(activity,edit_comment,true); ToastUtil.show(activity,"评论发布成功"); }else{ ToastUtil.show(activity,"评论不能为空"); }break;
评论列表的点击事件:
nelv_comment_detail为评论列表控件listview
nelv_comment_detail.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //显示输入法键盘,和edittext以及发送按钮 showSoftInputFromWindow(activity,edit_comment,false); commentId=mAdapter.getCommentList().get(position).getCommentId(); }});edittext和发送按钮的布局文件(部分):<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"><listview.../><LinearLayout android:layout_width="match_parent" android:layout_height="30dp" android:orientation="horizontal" android:layout_alignParentBottom="true" android:visibility="gone" android:id="@+id/ll_inputmethod" android:layout_marginBottom="@dimen/dimen_dp_5" android:background="@color/white" > <EditText android:layout_width="0dp" android:layout_weight="4" android:layout_height="match_parent" android:hint="写下你的评论吧..." android:textSize="@dimen/dimen_sp_13" android:textColor="@color/black" android:background="@drawable/inputmethod_edittextbg" android:padding="@dimen/dimen_dp_5" android:gravity="center_vertical" android:layout_marginLeft="@dimen/dimen_dp_5" android:id="@+id/edit_comment" /> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" android:textColor="@color/white" android:text="发送" android:id="@+id/tv_send" android:background="#5a718b" android:gravity="center" android:textSize="@dimen/dimen_sp_13" android:layout_marginLeft="@dimen/dimen_dp_10" android:layout_marginRight="@dimen/dimen_dp_5" /></LinearLayout></RelativeLayout>
阅读全文
0 0
- 需求实现:点击用户评论列表项,弹出输入法并进行编辑回复功能
- 实现评论,回复功能
- 仿微信评论点击弹出功能
- tp 实现无限回复评论功能
- Vue.js实现文章评论和回复评论功能
- 博客项目实现文章评论功能(重点是评论回复)
- 博客项目实现文章评论功能(重点是评论回复)
- 博客项目实现文章评论功能(重点是评论回复)
- magento 评论回复功能
- php 无线级别分类 实现评论回复功能
- 监听器--显示登陆用户列表,并实现踢人功能
- zencart 添加评论回复功能
- 评论回复功能数据表设计
- android 功能代码------点击EditText不弹出输入法
- Android 禁止点击输入法的回车键并弹出提示
- 实现类似微信朋友圈或者QQ空间,评论回复,九宫格布局。处理键盘弹出后定位到当前点击的被评论人处。另:滑动时候FPS在57-60之间,纵享丝滑
- iOS类似微信点击评论或者回复 键盘出来 点击评论动态所在cell动态调整到键盘上方 方便用户看到自己所评论的
- 实现列表CListCtrl可点击编辑
- bitset 入门——HDU 5036,HDU 5313,HDU 4920,POJ 2443
- 乱序字符串
- LoadRunner录制手机APP脚本
- python 动态调用模块内的函数
- 静态代码块、构造代码块和构造方法的执行顺序
- 需求实现:点击用户评论列表项,弹出输入法并进行编辑回复功能
- ip子网划分实例
- webpack入口起点
- 经历与经验
- tp5的美&&layui的酷
- idea maven SVN 导入工程后 maven projects 里面标红
- Jsoup爬虫工具实现背景图片爬取
- 运维之基础网络篇-----4. 包格式及IP地址 、 网络层协议及路由器
- 使用Git将代码上传到GitHub