I want to highlight a Particular row item in list view
to show as selected Item.
I have a list of countries I want highlight a single country so that it will be selected by a button.
I used this:
<ListView
android:id="@+id/list_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/doneBtn"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector"
android:layout_below="@+id/image_logo">
</ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/list_selector">
<TextView
android:id="@+id/country_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_gravity="center"
android:text="CountryName"
android:textSize="24sp"/>
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
mCountryAdapter = new CountryAdapter(this, R.layout.single_country, countryList);
mListViewCountry.setAdapter(mCountryAdapter);
mListViewCountry.setSelector(R.drawable.list_selector);
clickListeners();
}
here is my selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/color_selector"/>
<item android:state_selected="true" android:drawable="@color/color_selector"/>
</selector>
It is just changing color when I click or press on the item and if I remove touch, It is changing to default color! can any one help me what i'm missing