Emma.bk
Emma.bk

Reputation: 189

OnClick generate different Events when you click multiple times

I'm trying to get my OnClick to generate differente events when I click once or twice. On the first click the ImageView changes, on the second it pass to a different Activity.

Here's my code for now

public static int i=0;

final ImageView srt = findViewById(R.id.imageone);
Button apply = findViewById(R.id.apply);
       apply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE));
              if(i==0){
                  srt.setImageResource(R.drawable.imagetwo);
             }else{
                  Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                  startActivity(intent);
                }
            }
        });
    }

Right now if I click once the ImageView change, but the second click does not work and doesn't change the Activity.

Upvotes: 0

Views: 47

Answers (1)

BigBeef
BigBeef

Reputation: 141

I think Ritu Suman Mohanty in the comments is correct. You need to increment your value with i++; Right now, i == 0 is always true. Good luck!

Upvotes: 1

Related Questions