I try to use BaseAdapter to show item in ListView.
I try below code in BaseAdapter.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
//...
convertView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
v.setBackgroundResource(R.drawable.ic_corner_four_click);
break;
case MotionEvent.ACTION_UP:
v.setBackgroundResource(R.drawable.ic_corner_four);
break;
}
return false;
}
});
}
While item be touched, it change background to ic_corner_four_click.
But while release finger or move to other item, it did not rechange to ic_corner_four.
How to modify it?
You should use a
StateListDrawableto define the background in a specific state. See the documentation. If you look to the right of the question you can see other very similar questions. —>This one, for example.