我有一个基本上是调查活动的应用程序。有些问题要求在继续之前填写一组条件或另一组条件。
当用户按下是时,他们会得到一组 EditText 字段,如果他们按下否,他们会得到另一组。任何一种选择都会启用相同的继续按钮,但我需要检查是否只填写了两组中的一组,然后再继续下一个活动。
bContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (myYesSection.isShown() && valueCombined.getText().toString().isEmpty()){
Toast.makeText(getApplicationContext(), "Please enter the combined score.", Toast.LENGTH_LONG).show();
}
if (myNoSection.isShown() && valueOne.getText().toString().isEmpty() || valueTwo.getText().toString().isEmpty() || valueThree.getText().toString().isEmpty()){
Toast.makeText(getApplicationContext(), "Please fill out all fields.", Toast.LENGTH_LONG).show();
}
else{
Intent toNextActivity = new Intent(getApplicationContext(), QuestionThree.class);
startActivity(toNextActivity);
}
}
});
在操作中,如果valueCombined被填写,toast 会出现“请填写所有字段”。并且用户不会去下一个活动。如果valueCombined填写了,我不需要填写其他字段。
填写valueOne、valueTwo和valueThree允许打开下一个活动,但要敬酒“请输入综合分数”。
我必须更改什么以便按下按钮只需要两个条件之一才能继续?
更新工作代码感谢@Andreas 的课程。这会准确检查我需要什么,并且如果显示错误的条件集,则不会弹出错误的吐司:
bContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int count = 0;
if (combinedValue.getText().toString().isEmpty()){
if (myYesSection.isShown()) {
Toast.makeText(getApplicationContext(), "Please enter combined score.", Toast.LENGTH_LONG).show();
}
count++;
}
if (valueOne.getText().toString().isEmpty() || valueTwo.getText().toString().isEmpty() || valueThree.getText().toString().isEmpty()){
if (myNoSection.isShown()) {
Toast.makeText(getApplicationContext(), "Please fill out all fields.", Toast.LENGTH_LONG).show();
}
count++;
}
潇湘沐
相关分类