我有一个EditText其中 InputType 是数字的,以及一个TextView. 我想知道的是,当用户插入一些integer value中EditText,使在数字键盘店插入值“完成”按钮,在显示它TextView。我怎么能意识到这一点?谢谢!!!
我有这个代码:
public void display(View view) {
EditText edC = (EditText) findViewById(R.id.edC);
TextView tvD = (TextView) findViewById(R.id.tvDisplay);
try {
String creditsS = edC.getText().toString();
int credits = Integer.valueOf(creditsS);
tvD.setText(credits);
} catch(NumberFormatException nfe) {
tvD.setText("Couldn't parse.");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序并单击按钮时,应用程序崩溃.我也尝试过
int credits = Integer.parseInt(creditsS)
Run Code Online (Sandbox Code Playgroud)
不起作用.哪里出了问题?
顺便说一下,我无法打印堆栈跟踪,因为logcat继续显示无限循环等错误.谢谢.:)