Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i put different colors in ListView

i want to get the different colors in each row of the list view

but current only one color is shown

so how can i do this

ArrayAdapter<String> adapter=new ArrayAdapter<String(this,R.layout.latesthappenings,R.id.LH_Titles,titles);
            setListAdapter(adapter);

i want to different color in each row

please tell how can i do

thanks

like image 818
Yashpal Avatar asked Nov 04 '22 21:11

Yashpal


1 Answers

You can use anonymous ArrayAdapter you have to write code inside getView()

Sudo code

ArrayAdapter<String> adapter=new ArrayAdapter<String>(
           this,R.layout.main,R.id.textview1,titles){

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
if(position ==condition){
convertView.setBackgroundResource(R.color.grey);}
else if(second condition){convertView.setBackgroundResource(R.color.something else);}

    return view;};
   };

ANother approach is

Why donot you do for Customized ListView? You can manage view as per your requirement there.

Have a Custom ArrayAdapter

Thanks Deepak

like image 174
Sunil Kumar Sahoo Avatar answered Nov 15 '22 13:11

Sunil Kumar Sahoo