Reputation: 9013
I am working on a small android application. I have some dynamically added Relative layout. I have given background image in Action down (onTouchListener) and removed that image on Action up. But I have one problem. when I drag on that layout, the first image wont disappear. that is action up is not working. So what can I do for this problem. I want to give the selection effect as in list view.
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mCell.setBackgroundResource(R.drawable.gn_sudo_grille_selection);
Log.d("inside cell", "Touched");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mCell.setBackgroundResource(R.drawable.grile);
Log.d("inside cell", "Action-up");
}
return false;
}
Upvotes: 2
Views: 182
Reputation: 234795
Use a StateListDrawable as a background. I think that if you use android:pressed
as a selector, then it will automatically respond to touch events without any coding on your part at all.
Upvotes: 1