samedi 20 décembre 2014

Android to many if and else conditions

I'm using a shared preference to save users page number. So when user reloads the app they can continue reading from where they left off. They way I have done it works but feels messy as this would end having like 400 if and else conditions. Is there a better way to do this. Many thx



@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (firstcheck.getText().toString().equals("")){
SavePrefs("FIRST_CHECK", firstcheck.getText().toString());
Intent myIntent = new Intent(SplashActivity.this, ConfigurationActivity.class);
startActivity(myIntent);
}else{
if (firstcheck.getText().toString().equals("0")){
Intent myIntent = new Intent(SplashActivity.this, BackgroundActivity.class);
startActivity(myIntent);
}else{
if (firstcheck.getText().toString().equals("1")){
Intent myIntent = new Intent(SplashActivity.this, Page1Activity.class);
startActivity(myIntent);

Aucun commentaire:

Enregistrer un commentaire