1
我嘗試更改列表視圖中選定項目的背景,當滾動列表視圖時,我獲得了更多項目。 我知道它的發生,因爲我回收我的項目清單,但我找不到如何解決這個問題Android更改列表視圖中1項的背景顏色
這裏我的代碼: 類BabyAdapter擴展ArrayAdapter {
BabyHolder babyholder;
BabyAdapter(ArrayList<BabyHolder> list) {
super(BabyNames.this, R.layout.namerow, R.id.tvName, list);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
TextView tv = (TextView) row.getTag();
if(tv == null){
tv = (TextView) row.findViewById(R.id.tvName);
row.setTag(tv);
}
row.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
v.setBackgroundColor(Color.BLUE);
}
});
babyholder = getItem(position);
tv.setTag(Integer.valueOf(position));
tv.setText(babyholder.name);
return row;
}
}
public BabyHolder getItem(int position) {
return (((BabyAdapter) getListAdapter()).getItem(position));
}
感謝您的幫助:]