I know it sounds very simple, and there are questions about this. But none of it could solve my problem. So here we go:
I want to change background color of a list item
this is how I did it:
create a global variable View ColoredView
; then when you setOnItemClickListener
for your ListView
, do this:
MenuList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
if (ColoredView != null)
ColoredView.setBackgroundColor(Color.WHITE); //original color
view.setBackgroundColor(Color.BLUE); //selected color
ColoredView = view;
}
});
it's the simplest way in my opinion.