android listadapter
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); 开发者_JAVA技巧
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);
}
}
when i select an item random other items background also gets changed although they are not added to the array names and numbers.
i need only the background of the selected item tochange... is there a way to do this without creating my own listadapter ? ?
You should have a look to State List drawables which allow you to define different drawables for each possible states (focus, selected, pressed, etc).
https://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
精彩评论