This is my code and when I try to run it and when I select headache, sweating, weakness, chills, bone pain and joint pain viralfever.class activity gets started instead of chickengunia.class. What is the problem here?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questionnaire);
final Button go = (Button) findViewById(R.id.submit);
go.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, ViralFever.class);
startActivity(Intents);
}
else if (headache.isChecked() && bonepain.isChecked() && weakness.isChecked() && rashes.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Dengue.class);`enter code here`
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && skinyellow.isChecked() && palestools.isChecked() && abdoman.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Jaundice.class);
startActivity(Intents);
}
else if (diarrhea.isChecked() && sweating.isChecked() && nausea.isChecked() && dehydration.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Cholera.class);
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && shiver.isChecked()&& abdoman.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Malaria.class);
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked() && bonepain.isChecked() && jointpain.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Chickengunia.class);
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked()&& diarrhea.isChecked()&& nausea.isChecked()&& sorethroat.isChecked()&& cough.isChecked()&& runningnose.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Swineflu.class);
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked()&& rashes.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Typhoid.class);
startActivity(Intents);
}
else
{
Intent Intents = new Intent(Questionnaire.this, Checkup.class);
startActivity(Intents);
}
}
});
}
}
This is my class file and it executes only the first if statement because the buttons I selected are in that statement.
Причина:
Проблема, похоже, в том, что ваш чек на ViralFever написан перед выпиской Chickengunia. Что происходит, так это то, что сначала он проверяет симптомы для ViralFever, который имеет то же подмножество симптомов, что и Chickengunia.
Решение:
Что вы можете сделать, так это поменять местами код для ViralFever и Chickengunia.
if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked() && bonepain.isChecked() && jointpain.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, Chickengunia.class);
startActivity(Intents);
}
else if (headache.isChecked() && sweating.isChecked() && weakness.isChecked() && chills.isChecked()) {
Intent Intents = new Intent(Questionnaire.this, ViralFever.class);
startActivity(Intents);
}
и так далее...
if (isHeadeck&& isPain&&isSweat&&isChills){
if (jointPin&&isBonepain)
Intent Intents = new Intent(Questionnaire.this, Chickengunia.class);
startActivity(Intents);
else
Intent Intents = new Intent(Questionnaire.this, ViralFever.class);
startActivity(Intents);
}
условия для вирусной лихорадки - это подмножество цыпленка, означает, что если цыпленок верен, то вирусный должен быть истинным. Поскольку сначала выполняется условие вирусного класса, вы будете перенаправлены на вирусную страницу. Попытайтесь создать разницу в логике для обоих и на основе этого перенаправления на нужную страницу