求一个android小程序代码 在文本框1和文本框2输入一个数字,文本框3中显示前面两个文本框数字和的个位数
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
展开全部
文本框1,2,3以下简写为et1,et2,et3
初始化的代码就不写了,按你的layout里的id为准。之后的代码这么写:
et1.addTextChangedListener(watcher);
et2.addTextChangedListener(watcher);
private TextWatcher watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
int a = Integer.parseInt(et1.getText().toString);//实际上要捕获异常,这里就偷个懒
int b = Integer.parseInt(et2.getText().toString);//同上
int sum = a+b;
String text = sum+"";
et3.setText(text .subString(text.length()-1,text.length());
}
};
初始化的代码就不写了,按你的layout里的id为准。之后的代码这么写:
et1.addTextChangedListener(watcher);
et2.addTextChangedListener(watcher);
private TextWatcher watcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
int a = Integer.parseInt(et1.getText().toString);//实际上要捕获异常,这里就偷个懒
int b = Integer.parseInt(et2.getText().toString);//同上
int sum = a+b;
String text = sum+"";
et3.setText(text .subString(text.length()-1,text.length());
}
};
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询