mardi 27 mars 2018

Java: Stuck inside if statement block

i am starting with creating android apps, i already have some basic experience with C# and Java. Now i'm stuck at a strange problem, see below:

public void pictureSwitch (View view){
    ImageView imageView = (ImageView) findViewById(R.id.imgVCat);
    boolean switched = false;

    if (switched){
        imageView.setImageResource(R.drawable.catstart);
        Log.i("Status-Start", "Wert: " +  switched);
        switched = false;
    } else {
        imageView.setImageResource(R.drawable.catswitch);
        Log.i("Status-switched", "Wert: " +  switched);
       switched = true;
    }

    }

}

The Problem is, on the first click on the Button it changes to the catswitch drawable. But it never switches back and i dont know why.

Thanks for your help in advance.

Aucun commentaire:

Enregistrer un commentaire