我想在单击列表项时更改它的背景,但它不起作用。
这是我的 MusicAdapter 内部类:
class MusicAdapter extends ArrayAdapter<String>{
Fill fill=null;
public MusicAdapter(){
super(GetMusics.this,android.R.layout.simple_list_item_1,song_list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
row = convertView;
if(row==null){
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.row, null);
fill=new Fill(row);
row.setTag(fill);
}else{
fill=(Fill)row.getTag();
}
row.setBackgroundResource(R.drawable.list_selector);
fill.setRow(song_list.get(position));
return row;
}
}
我也试过这个,但还是不行:
private AdapterView.OnItemClickListener onItemClick = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {
// TODO Auto-generated method stub
lv.getChildAt(arg2).setBackgroundResource(R.drawable.list_selector);
}
};
这是我的 list_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true"
android:drawable="@color/Peru"/>
<item android:state_pressed="true"
android:drawable="@color/Tan"/>
<item
android:drawable="@color/Peru"/>
</selector>
你有什么建议吗?