【Android进阶学习】监听EditText的变化
来源:互联网 发布:百年孤独中的女性 知乎 编辑:程序博客网 时间:2024/06/11 19:57
MainActivity.javapackage com.lingdududu.watcher; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.widget.EditText; public class MainActivity extends Activity { private EditText text; String str; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); text = (EditText)findViewById(R.id.text); text.addTextChangedListener(textWatcher); } private TextWatcher textWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub Log.d("TAG","afterTextChanged--------------->"); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub Log.d("TAG","beforeTextChanged--------------->"); } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { Log.d("TAG","onTextChanged--------------->"); str = text.getText().toString(); try { //if ((heighText.getText().toString())!=null) Integer.parseInt(str); } catch (Exception e) { // TODO: handle exception showDialog(); } } }; private void showDialog(){ AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("消息").setIcon(android.R.drawable.stat_notify_error); builder.setMessage("你输出的整型数字有误,请改正"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); dialog = builder.create(); dialog.show(); } }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="请输入整型数字"
- />
- <EditText
- android:id="@+id/text"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
0 0
- 【Android进阶学习】监听EditText的变化
- 【Android进阶学习】监听EditText的变化
- 【Android进阶学习】监听EditText的变化
- 【Android进阶学习】监听EditText的变化
- 【Android进阶学习】监听EditText的变化
- 【Android进阶学习】监听EditText的变化
- android 监听EditText 的变化
- android 监听EditText的变化
- Android---监听EditText变化
- Android开发:监听EditText字数的变化
- Android开发教程:监听EditText的变化
- Android开发教程:监听EditText的变化
- 监听EditText的变化
- 监听EditText的变化
- 监听EditText的变化
- 监听EditText的变化
- 监听EditText的变化
- 监听EditText的变化
- 设计模式--单例模式(线程安全)
- 图像缩放
- JFreeChart与springMVC 或servlet整合
- 项目开发步骤
- 移植Qt之更改分辨率问题
- 【Android进阶学习】监听EditText的变化
- tp 中的I()方法
- 如何用C语言实现转转相除法求最大公约数和最小公倍数
- Total Highway Distance(贪心)
- Linux操作系统——Windows 10 下的 Linux(Ubuntu)
- Hadoop集群集成kerberos
- 正则表达式
- 各种分布式文件系统简介
- mongodb的启动与关闭