任何人都可以建议为什么整数值没有显示在 Android 对话框窗口的 TextView 中。我使用下面的代码来显示对话框窗口
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.btnAccountInfo) {
this.showDialog(DIALOG_ACCOUNT);
}
}
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_ACCOUNT:
final Dialog info = new Dialog(this);
info.setContentView(R.layout.accountinfo);
info.setTitle("User Account for MobileProtect");
backInfo = (Button) info.findViewById(R.id.backInfo);
userNumber1 = (TextView)info.findViewById(R.id.textUserNumber1);
userNumber2 = (TextView)info.findViewById(R.id.textUserNumber2);
userEmail = (TextView)info.findViewById(R.id.textUserEmail);
Log.d("User Number", "Dialog: "+number1+number2);
userNumber1.setText(number1);
userNumber1.setText(number2);
userEmail.setText(email);
backInfo.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
info.dismiss();
}
});
return info;
}
return null;
}
Number1 和 Number1 未显示在对话框窗口中,而电子邮件显示在对话框窗口中。我已经检查了 logcat,我得到了 number1 和 number2 的值,并且也是整数格式。 有什么建议吗?
最佳答案
将 int 传递给 setText
方法将调用一个重载,该重载将参数解释为资源 ID。请参阅documentation了解更多信息。使用这个代替
userNumber1.setText(Integer.toString(number1));
还要考虑改进变量名称并格式化代码。
关于java - 在 Android 对话框窗口的 TextView 中显示整数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8182936/