Morten
Morten

Reputation: 7

How to change background color of a listitem

I'm trying to change the color of some of the items in a list but not all off them. Im using a adaptor to incorperate the list so that it is show when i press a button. Now i cant figure out where I can get to the attributes (like background color) of the list item.

The code looks like this

public void visskema(View view) {

    Calendar date =Calendar.getInstance();
    /*redigerer for offset*/
    long oldtime =date.getTimeInMillis();
    long newtime= oldtime +((long)offsetuger*7*1000*3600*24);
    date.setTimeInMillis(newtime);
    int weekofyear= date.get(Calendar.WEEK_OF_YEAR);
    int dayofmonth= date.get(Calendar.DAY_OF_MONTH);
    int month=date.get(Calendar.MONTH)+1;
    int year=date.get(Calendar.YEAR);

    Vector<Skemabrik> aktuelskema =webservicegetskemauge(username,domain,dayofmonth,month, year,weekofyear);
    Vector<Skemabrik> sortetskema=sortskema(aktuelskema);
    Vector<Skemabrik> endeligtskema=padskema(sortetskema);
    if(endeligtskema.size()>0)
    {
        String[] fag =new String[endeligtskema.size()];
        for(int i=0;i<endeligtskema.size();i++)
        {
            Skemabrik brik =endeligtskema.get(i);
            String temp =brikToString(brik);    
            fag[i]=temp;
        }
        ListView lv = new ListView(this); 
        //final TextView citytext = (TextView) findViewById(R.id.CITY);
        lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,fag)); 

        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // When clicked, show a toast with the TextView text
                //  System.out.println("bøh" + listtext);
                setContentView(R.layout.skemauge);



                //  der skal sætttes billedet med de to knapper city og country og udfyldes værdi for country og city
            }
        });
        setContentView(lv);
    }
    else{
        setContentView(R.layout.skemauge);
        TextView Eugenummer = (TextView) findViewById(R.id.ugenummer);  
        Eugenummer.setText("Du har ingen timer i denne uge");
    }
}

if anybody could tell me how and where to get the the textview in the adaptor so i can change the background color i would appreciate it :) (im rather new at android :D)

Upvotes: 0

Views: 1035

Answers (1)

ernazm
ernazm

Reputation: 9268

You have to implement your own custom list adapter and override getView method. You could refer to this example

Upvotes: 1

Related Questions