I want click effect when image is clicked but from my code whenever i click image for the first time nothing happen however when i click for second time it shows orange colour effect that image was clicked . Below is my code ,I know this might not be the correct way to do this . But i want to know why this is happening
image.xml
<ImageView
style="@style/icon"
android:background="@drawable/fear_96"
android:onClick="see"
android:id="@+id/abulation"
/>
below is onclick method
public void see(View view) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
view.getBackground().setColorFilter(0xf0f47521,
PorterDuff.Mode.SRC_ATOP);
view.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
view.getBackground().clearColorFilter();
view.invalidate();
startActivity(view.getId());
break;
}
return true;
}
});
}
public void startActivity(int id)
{
Intent intent=new Intent(this,DuwaListView.class);
switch (id)
{
case R.id.abulation:
intent.putExtra(Intent.EXTRA_TEXT,"Abulation");
break;
case R.id.dressing:
intent.putExtra(Intent.EXTRA_TEXT,"Dressing");
break;
case R.id.restroom:
intent.putExtra(Intent.EXTRA_TEXT,"Restroom");
break;
default:
Toast.makeText(this,"underconstruction",Toast.LENGTH_SHORT).show();
return;
}
startActivity(intent);
}
Please help why this code is showing such behaviour