Я хочу выделить конкретный элемент строки в list view
, чтобы отобразить выбранный элемент.Как выделить ListItem в виде списка?
У меня есть список стран, в которых я хочу выделить одну страну, чтобы она была выбрана кнопкой.
Я использовал это:
<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();
}
вот мой селектор:
<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>
Это просто изменение цвета при нажатии или нажмите на пункт и, если удалить контакт, он меняется на цвет по умолчанию! Может ли один помочь мне, что я не хватает
это можно сделать с помощью этого [введите описание ссылки здесь] (http://stackoverflow.com/questions/39696340/accessing-listview-checkbox- in-android/39697518 # 39697518) – kggoh