android获取edittext中的值并相加,将得到的数值显示在另一textview中 30
publicclassMainActivityextendsActivity{EditTexttxtMorning,txtNoon,txtNight,txtLate,tx...
public class MainActivity extends Activity {
EditText txtMorning,txtNoon,txtNight,txtLate,txtPlay,txtStudy;
Button btnplSave;
TextView txtTotal;
private int morning,noon,night,late,play,study,planMoney;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.plan);// 设置布局文件
txtMorning=(EditText) findViewById(R.id.txtMorning);
txtNoon=(EditText) findViewById(R.id.txtnoon);
txtNight=(EditText) findViewById(R.id.txtNight);
txtLate=(EditText) findViewById(R.id.txtLate);
txtPlay=(EditText) findViewById(R.id.txtPlay);
txtStudy=(EditText) findViewById(R.id.txtStudy);
txtTotal=(EditText) findViewById(R.id.txtTotal);
btnplSave=(Button) findViewById(R.id.btnplSave);
morning=Integer.parseInt(txtMorning.getText().toString());
noon=Integer.parseInt(txtNoon.getText().toString());
night=Integer.parseInt(txtNight.getText().toString());
late=Integer.parseInt(txtLate.getText().toString());
study=Integer.parseInt(txtStudy.getText().toString());
play=Integer.parseInt(txtPlay.getText().toString());
planMoney=morning+noon+night+late+play+study;
txtTotal.setText(planMoney+"");
}
}
这样做为什么不对,没有判断是否为空还是什么 展开
EditText txtMorning,txtNoon,txtNight,txtLate,txtPlay,txtStudy;
Button btnplSave;
TextView txtTotal;
private int morning,noon,night,late,play,study,planMoney;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.plan);// 设置布局文件
txtMorning=(EditText) findViewById(R.id.txtMorning);
txtNoon=(EditText) findViewById(R.id.txtnoon);
txtNight=(EditText) findViewById(R.id.txtNight);
txtLate=(EditText) findViewById(R.id.txtLate);
txtPlay=(EditText) findViewById(R.id.txtPlay);
txtStudy=(EditText) findViewById(R.id.txtStudy);
txtTotal=(EditText) findViewById(R.id.txtTotal);
btnplSave=(Button) findViewById(R.id.btnplSave);
morning=Integer.parseInt(txtMorning.getText().toString());
noon=Integer.parseInt(txtNoon.getText().toString());
night=Integer.parseInt(txtNight.getText().toString());
late=Integer.parseInt(txtLate.getText().toString());
study=Integer.parseInt(txtStudy.getText().toString());
play=Integer.parseInt(txtPlay.getText().toString());
planMoney=morning+noon+night+late+play+study;
txtTotal.setText(planMoney+"");
}
}
这样做为什么不对,没有判断是否为空还是什么 展开
2个回答
展开全部
oncreate方法中执行计算的代码,editview内容是空的吧。。。你还是把计算的逻辑放其他方法里面,做好异常处理。点击button时候调用。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询