I am attempting to update the background color of a list item when it is selected and keep the changes even if the view changes. My update works as expected when I click on the item but can not get it to maintain the changes if I leave the view. I thought that making the same update in the getView () method would give me what I needed but it doesn't seem to work. Any suggestions?
public class MyScaAdapter extends SimpleCursorAdapter {
public MyScaAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, con开发者_如何学GovertView, parent);
if (convertView == null & position == selectedPos) {
v.setSelected(true);
v.setBackgroundColor(android.R.color.background_light);
}
return v;
}
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
v.setSelected(true);
v.setBackgroundColor(android.R.color.background_light);
selectedPos = position;
}
Maintain a global reference to the view so that you can set your background color in the onResume()
method.
精彩评论