开发者

How to use different backgrounds for ListView entries?

开发者 https://www.devze.com 2023-03-15 12:30 出处:网络
I\'ve got a ListView and I\'m trying to use different backgrounds for the entries, how can I specify which entry should get which background?

I've got a ListView and I'm trying to use different backgrounds for the entries, how can I specify which entry should get which background?

What I'm doing is that I load the entries in the code, here:

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, listEntries));

So how can I specify a layout for every entry?

Kind Re开发者_开发知识库gards Sam


Write you own adapter that extends ArrayAdapter and override public View getView(int position, View convertView, ViewGroup parent) method like this

View view;
String myString = getItem(position);
if (convertView == null) {
        LayoutInflater inflater = context.getLayoutInflater();
        view = inflater.inflate(R.layout.list_item, null);            
    } else {
        view = convertView;
    }
// here you can change background of view
return view;
0

精彩评论

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