How to use different backgrounds for ListView entries?
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;
精彩评论