samedi 28 mars 2015

How do I rewrite if into switch with cases as strings in android app?

I m detecting which button i clicked:



public void next_page(View view){

//if else - works:

if( view.getId() == "fly_button")
Log.d(LOG, " fly button clicked");
else if (view.getId() == "imageButton")
Log.d(LOG, "image button clicked");

//switch does not work:
// every id is a string, how to show it as integer in "case"?

switch( view.getId() ){
case "fly_button":
Log.d(LOG, "fly button clicked");
case "imageButton":
Log.d(LOG, "image button clicked");
}

Aucun commentaire:

Enregistrer un commentaire