How can I change the background of a single cell of a ListView? I wrote in java:
n_list = new ListView(this);
n_list.setBackgroundDrawable(getResources().getDrawable(R.drawable.list_pressed));
This way changes the background of the whole list. When I press on a cell it changes the background of all cells.
list_pressed.xml
on drawable
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:drawable="@drawable/listviewpress" />
<item android:state_pressed="true"
android:drawable="@drawable/listviewpress" />
<item
android:drawable="@drawable/listview" />
</selector>
How can I fix this? Thanks in advance :)
You need to create a Custom Adapter and in the getView()
you can say what color you want to give to your row.
If you follow the tutorial on the link you can do on your convertView
a setBackground()
with the color you want. If you want a specific position just do an if before that setBackground
.