I basically want to customize list item`s background color while it is touched. I tired writing a listener but it seams that I made some kind of mistake or misunderstood the concept of these actions.
v.setOnTouchListener( new TextView.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setBackgroundColor(Color.RED);
break;
case MotionEvent.ACTION_UP:
v.setBackgroundColor(Color.WHITE);
break;
}
return false;
}
}
);
Default color is light blue. I want to change it for every list item.
This code changes items color to red when touched but it does not change back after that.
But maybe the best would be to use color states…create a file mycolors.xml in the color folder with this:
then later you set the background of the view like this: android:background=”@color/mycolors” in the layout xml or programmatically like this: v.setBackgroundColor(getResources().getColor(R.color.mycolors);
no clicks or touch listeners will be necessary in this case..everything will happen magically.
more about it: http://developer.android.com/guide/topics/resources/color-list-resource.html