Android 软键盘按键监控
来源:互联网 发布:老电视能看网络电视吗 编辑:程序博客网 时间:2024/06/06 07:33
最近在做项目,遇到一个比较头疼的问题,问题是需要对用户的输入进行时时监听,而大部分用户的输入是通过软键盘来完成的,而Android平台好象没有专门的对此监控事件,那该怎么办呢?
最终解决办法就是通过EditText和TextWatcher类来辅助监听。具体做法如下:
private class TextMonitor implements TextWatcher{ @Overridepublic void beforeTextChanged(CharSequence s, int start, int count,int after) {//输入前的内容String str_forward=s.toString().length();}@Overridepublic void onTextChanged(CharSequence s, int start, int before,int count) {//正在输入的内容String str=s.toString().substring(start);tv.setText("您已经编辑的内容:"+s.toString());if(str.contains("\n")){//回车键}}@Overridepublic void afterTextChanged(Editable s) {//输入后的内容String str_last=s.toString().length();} }
相应控件:
private TextView tv;private EditText edit;tv=(TextView)findViewById(R.id.showInput);edit=(EditText)findViewById(R.id.InputContent);edit.addTextChangedListener(new TextMonitor());
布局文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/showInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="显示您的编辑内容" /> <EditText android:id="@+id/InputContent" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="输入编辑内容" /></LinearLayout>
目前好像还没有其他的好办法,只能这样间接监控,欢迎大家能提出更好的解决办法。
- Android 软键盘按键监控
- Android 监听软键盘按键
- Android 监控软键盘状态
- android:imeOptions 控制软键盘右下角按键
- android软键盘右下角按键设置
- Android EditText 软键盘按键设置
- Android监控软键盘变化实例
- Android软键盘弹出或关闭监控
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App三种监听软键盘按键
- Android 监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- Android App监听软键盘按键的三种方式
- C++ 虚函数表解析
- HDU4404 Worms
- java jdk1.6内置支持的webservice使用示例
- 异或 算法 小总结
- 【服务器】基于jabber(XMPP)架设内部即时通讯服务
- Android 软键盘按键监控
- Java学习(回顾)笔记之day3
- pkgm : 动态压缩包维护与安装脚本
- HDU4405 Aeroplane chess
- Java学习(回顾)笔记之day4
- 这几天心里颇不宁静
- PHP 分页类
- C++ 特殊机制收集
- 这几天写的几个小程序