I have a custom listview
in my android application. When a user press an item in the list I want to change the background color of the pressed item. This is the code for that behaviour:
tempView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
isDown = false;
tempView.setBackgroundColor(Color.parseColor("#f47920"));
}
if (event.getAction() == MotionEvent.ACTION_UP) {
tempView.setBackgroundResource(R.drawable.list_selector_focused);
}
if(event.getAction() == MotionEvent.ACTION_MOVE) {
tempView.setBackgroundResource(R.drawable.list_selector_focused);
}
return false;
}
});
But when I "Fling" my finger over the screen to scroll the listview
, an item is also marked, and the "pressed" color will be static. How can I avoid this?