java - Change Background color item of ListView while maintaining effect of custom Drawable -


i try change background color @ specific item within listview, while maintaining effect of 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 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 change color when item 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 above code, the background color of fourth item changed, no longer affected custom drawable :

[..] <item android:drawable="@color/orange_off" android:state_pressed="true"/>   [..] 

so, how can change background color of 1 item while maintaining effects of drawable on item ?

why not create drawable color , set drawable if position 4:

@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.drawable.background_list_mauve);          }     return v; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -