清水鼻涕泡
2017-09-05 13:06安卓对Edittext监听的问题
public class MainActivity extends ActionBarActivity {
private EditText first;
private EditText second;
private TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
first =(EditText) findViewById(R.id.first);
second=(EditText) findViewById(R.id.second);
result=(TextView) findViewById(R.id.result);
first.addTextChangedListener(textwatcher);
second.addTextChangedListener(textwatcher);
}
private TextWatcher textwatcher =new TextWatcher() {
int f=Integer.parseInt(first.getText().toString());
int s=Integer.parseInt(second.getText().toString());
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
result.setText(f+s);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
};
为什么编译时没有显示错误 但运行在模拟器上确程序出错停止运行了呢(XML文件是对的)
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 为什么运行查询和删除数据库时闪退?
- android-studio
- android
- 2个回答
- android程序的监听器相关问题
- android
- 0个回答
- 我的这个程序在没有Button监听的时候没有出错 可是加上了一个Button监听就不能运行了是为什么啊?
- android
- 0个回答
- android 百度地图 搜索跳转
- 百度
- android
- 搜索
- list
- 4个回答
- listview 多个item嵌套多个edittext 如何对相应item的edittext进行操作
- 5个回答
换一换