Issue
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.
Solution
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!
Answered By - BigBeef
Answer Checked By - Pedro (JavaFixing Volunteer)