我有2个EditText
来获得String
,点击Button
后,它会将此char
的{{1}}转换为String
。然后,它会对int
的所有int
求和,当chars
的总和为int
时,(totals&1 == 0)
显示“这是奇数”。在Dialog
后,第二个else,
显示“即使是”。我需要设置Dialog
来显示。
AlertDialog
答案 0 :(得分:2)
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("that is odd");
builder.setCancelable(true);
AlertDialog alert = builder.create();
alert.show();
只写#34;即使是#34;而不是"这是奇怪的"对于第二个对话框。
答案 1 :(得分:0)
为此目的使用Toast,对于单个消息来说,它们更容易和快速。
Toast.makeText(this, "Your Message here",
Toast.LENGTH_LONG).show();
答案 2 :(得分:0)
btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { AlertDialog.Builder builder = new AlertDialog.Builder(StartActivity.this); builder.setMessage("that is odd"); builder.setCancelable(true); AlertDialog alert = builder.create(); String dataF = ed1.getText().toString(); char[] charArray = dataF.toCharArray(); int totalF = 0; for (char ch: charArray) { totalF += characterMap.get(ch); } String dataM = ed2.getText().toString(); char[] charArr = dataM.toCharArray(); int totalM = 0; for (char ch2: charArr) { totalM += characterMap.get(ch2); } int sum = totalF + totalM; int totals = sum % 5; if ((totals & 1) == 0) alert.show(); else { AlertDialog.Builder builder1 = new AlertDialog.Builder(StartActivity.this); builder1.setMessage("that is even"); builder1.setCancelable(true); AlertDialog alert1 = builder1.create(); alert1.show(); } } });