I created an application that have 4 activities: login, sport, technology and sporttechnology. the login activity that contains two check boxes in a listview (named sport and technology) and a button, when press the button the program check the text of the checked check boxes and opens the right activity based on it, if only the sport checkbox have been checked it should opens the sport activity, if only the technology checkbox have been chosen then it will open the technology activity, if both checkboxes have been checked then it will open an activity named "sporttecknology". when run the app, when I choose only the sport checkbox and then press the button, it opens the sport activity. but when I choose only the technology checkbox and then press the button the app stop working, and also that happens when I choose both checkboxes then press the button,
so is there any error in my code?
private void checkButtonClick() {
Button myButton = (Button) findViewById(R.id.findSelected);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer responseText = new StringBuffer();
//responseText.append("The following were selected...\n");
ArrayList<Interestclass> interestList = dataAdapter.interestList;
for (int i = 0; i < interestList.size(); i++) {
Interestclass interest = interestList.get(i);
if (interest.isSelected()) {
responseText.append(interest.getName());//"\n" +
}
}
Toast.makeText(getApplicationContext(), responseText, Toast.LENGTH_LONG).show();
String start = responseText.toString();
if (start.equals("Sport")) {
Intent intentSport = new Intent(MainActivity.this, Sport.class);
startActivity(intentSport);
}
else if (start.equals("Technology")) {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
else if (start.equals("SportTechnology")) {
Intent intentSportTech = new Intent(MainActivity.this, SportTechnology.class);
startActivity(intentSportTech);
}
else {
Intent intentTechnology = new Intent(MainActivity.this, Technology.class);
startActivity(intentTechnology);
}
/* switch (start) { case "Sport": Intent intentSport = new Intent(MainActivity.this, Sport.class); startActivity(intentSport); break; case "Technology": Intent intentTechnology = new Intent(MainActivity.this, Technology.class); startActivity(intentTechnology); break; }*/ }
});
}
Aucun commentaire:
Enregistrer un commentaire