Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所有-我有一个应用程序,用户在其中将值输入到多个编辑文本字段中,然后用户点击一个按钮来计算所有输入到公式中的数字并输出答案。我的问题是,当其中一个 edittect 字段留空时,当点击计算按钮时应用程序强制关闭。我知道我可以通过在点击计算按钮并且有一个或多个空的编辑文本字段时弹出一个警告对话框来解决此问题。我不知道如何将警报对话框放在“if”语句中。例如“如果任何一个编辑文本字段为空 .show() 这个警报对话框”。有人可以给我一些示例代码。
如果您有(或创建)所有字段的数组/列表EditText,您可以像这样运行它们
EditText
for(EditText e : editTextList) { if(e.getText().toString().length() == 0) { //Show dialog break; } }
您可以像这样创建一个EditTexts 列表:
List<EditText> editTextList = new ArrayList<EditText>();
然后添加
editTextList.add(myEditText);