protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Cursor c = (Cursor) mAdapter.getItem(position);
String a = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String b = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (names != null)
{
if(numbers.contains(b))
{
names = names.replace(a+";", "");
numbers = numbers.replace(b+";", "");
v.setBackgroundResource(R.drawable.background);
}
else{
names = names + a + ";";
numbers = numbers + b + ";";
v.setBackgroundResource(R.drawable.background_sel);
}
}
else
{
names = a+";";
numbers = b+";";
v.setBackgroundResource(R.drawable.background_sel);
}
}当我随机选择一个项目时,其他项目的背景也会发生变化,尽管它们没有添加到数组名称和编号中。
我只需要所选项目的背景就可以更改...有没有办法在不创建自己的listadapter的情况下做到这一点?
发布于 2010-09-07 06:56:40
您应该查看状态列表可绘制项,它允许您为每种可能的状态(焦点、选定、按下等)定义不同的可绘制项。
https://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
https://stackoverflow.com/questions/3653447
复制相似问题