Reputation: 6196
I am working in android.
I have a list of place. I want that whenever i click on a place from this list. Then color of that selected row should be changed to BLUE for a short time so it seems to be clicked.
this is the code which i trying:-
mListView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long duration)
{
view.setBackgroundResource(R.drawable.fsq_custom_background);
}
}
This is fsq_custom_background.xml which is stored in drawable folder:-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/the_background_color" />
</selector>
this is the_background_color.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF1212" />
</shape>
but still color of selected row is not changed. please help me what mistake i have done. Thank you so much.
Upvotes: 0
Views: 219
Reputation: 1934
First of all remove the code of changing bg color from onItemClick. It is for more valuable operations to be performed rather than just changing color of list row.
You can provide in the xml file where you have made your listView Object:
< ListView
android:listSelector=""
..... />
or
you can provide it as the background of the layout of the row of the list in xml.
Upvotes: 1