I have a custom listview
with a setOnTouchListener
view.setOnTouchListener(new OnTouchListener() {
@Override
publi
If you want to highlight ListView item on click/touch than it's better to use selectors instead of overiding OnTouchListener().
If you want to set the color, you need a StateListDrawable. You can set this on your list using the android:listSelector attribute, defining the drawable in XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/item_disabled" />
<item android:state_pressed="true"
android:drawable="@drawable/item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/item_focused" />
</selector>
Or you can use the same selector for item of the ListView.
What is the view in your case? Is it an individual list item or main listview ? If it is a listview, then try to handle the case
case MotionEvent.ACTION_MOVE :
//Check position here, if it is out of your view, then change the color back.
In your case you need either ACTION_UP or ACTION_DOWN event not ACTION_MOVE so to avoid ACTION_MOVE you can do something like this:
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
isDown = false;
}
if(event.getAction() == MotionEvent.ACTION_UP && !isDown)
{
// action you want to perform
}
if(event.getAction() == MotionEvent.ACTION_MOVE)
{
isDown = true;
}
as far as changing color is concerned, you can store previous view in a global variable and while going for next touch, you can change that global view color to normal.