I try to change the background color at specific item within my ListView, while maintaining the effect of the custom Drawable.
My custom list_items :
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
style="@android:style/TextAppearance.Holo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_list"
android:textColor="@color/white" />
My custom ArrayAdapter :
public class MissionDataListAdapter extends ArrayAdapter {
private final ArrayList<MissionData> list_missions;
public MissionDataListAdapter(Context context, int textViewResourceId, ArrayList<MissionData> objects) {
super(context, textViewResourceId, objects);
this.list_missions = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View v = super.getView(position, convertView, parent);
MissionData mission = list_missions.get(position);
if(position==4){
v.setBackgroundResource(R.color.mauve);
}
return v;
}
}
My Layout for my Activity :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/border_list"
android:orientation="vertical" >
<ListView
android:id="@+id/missionsListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:divider="@color/blue2"
android:dividerHeight="1dp" />
</LinearLayout>
My custom drawable for change the color when item is pressed :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/orange_off" android:state_pressed="true"/>
</selector>
public class MissionsListActivity extends Activity implements OnClickListener {
[..]
MissionDataListAdapter arrayAdapter;
ArrayList<String> donnees_parses;
ArrayList<MissionData> missions;
ListView missionsListView;
MissionData selectedmission;
MissionsDAO missionsBdd;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.missions);
[..]
missionsListView = (ListView)this.findViewById(R.id.missionsListView);
int layoutID = R.layout.list_items;
arrayAdapter = new MissionDataListAdapter(this, layoutID , missions);
missionsListView.setAdapter(arrayAdapter);
}
[..]
For the above code, the background color of fourth item its changed, but is no longer affected by the custom Drawable :
[..]
<item android:drawable="@color/orange_off" android:state_pressed="true"/>
[..]
So, how can I change the background color of one item while maintaining the effects of Drawable on my item ?