开发者

how can i put different colors in ListView

开发者 https://www.devze.com 2023-03-10 09:26 出处:网络
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

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

t开发者_如何学编程hanks


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


Set all the different colors (that you want in your list) codes in an array and fetch color code from that array for each row position and use setBackgroundColor() method to set that background color to the list row.

Try this.

0

精彩评论

暂无评论...
验证码 换一张
取 消