I have a ScrollView with a series of linearlayout textviews. When the user "touches" one of those textviews, I am temporarily changing the background color to "show" the touch so they can visually confirm the item they touched. When they lift their finger, I am changing the background color back to the default color.
I was having a problem that if they user scrolled, the ACTION_UP didn't seem to fire so that textview's background never changed back to default.
I thought I fixed it by adding an ACTION_MOVE to my TouchListener and that seemed to correct the problem, better, but not always.
My code looks like this...
mytextview.setOnTouchListener(mytouch);
along with...
private View.OnTouchListener mytouch = new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
v.setBackgroundColor(getResources().getColor(R.color.mytouchcolor));
}
if (event.getAction() == MotionEvent.ACTION_UP) {
v.setBackgroundColor(getResources().getColor(R.color.mydefaultcolor));
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
v.setBackgroundColor(getResources().getColor(R.color.mydefaultcolor));
}
return false;
}
}
This code WORKS if I...
- touch and release
- touch, slowly scroll, then release.
If I touch and quick scroll (or flick), the ACTION_UP or ACTION_MOVE never seems to fire (according to some LOG.I()
tests.
How can I fix this so that the background color ALWAYS turns back to default once the touch is lifted... scrolling or not?