When developing an application, I encountered such a problem. I have a ListView . It is necessary that when you click on an item, this item changes its appearance (text color), and when you click again, it returns to its normal state. The difficulty is that it should be saved, i.e. When restarting the application, the appearance of the items should be the same as when closing.

PS List items are pulled from the base, if it helps something.

    1 answer 1

    It should be like this: We declare the TextView (my_text_view.xml) layout

     <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textView" android:textColor="@color/myColor" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 

    We get a list:

     ListView listView = new ListView(context); String[] items = {"Item 1","Item 2", "Item 3"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.my_text_view,items); listView.setAdapter(ad); 

    Further, when clicking on an item:

     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long i) { ((TextView) view).setTextColor(anyColor); //вставляем свой цвет } }); 
    • everything is fine, but I already thought of it myself. there was another question, how to save, I know what to write to the database, but again how? and how to re-click the adapter to return to the standard state. - Vladimir Fedulkin
    • This is another question. Ask it in the prescribed order - Barmaley
    • I asked the appropriate question here: hashcode.ru/questions/136725/… - Vladimir Fedulkin