0
我正在執行一個列表。有它的項目數量,當我從列表中選擇一個項目設置列表項目的顏色。當我滾動列表視圖它消失。在列表視圖中滾動選擇的項目後臺colr消失了嗎?
可能是什麼原因?對於適配器 代碼給出如下:
public class CustomListViewAdapterProduct extends
ArrayAdapter<HashMap<String, Object>>
{
Context context;
public CustomListViewAdapterProduct(Context context, int resourceId,
ArrayList<HashMap<String, Object>> Strings) {
super(context, resourceId, Strings);
this.context = context;
}
/* private view holder class */
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item_detail, null);
holder = new ViewHolder();
holder.txtProduct = (TextView) convertView.findViewById(R.id.product);
holder.txtCode = (TextView) convertView.findViewById(R.id.code);
convertView.setTag(holder);
convertView.setBackgroundResource((position % 2) == 0 ? R.color.light
: R.color.dark);
} else {
if (position == selectedPosition) {
convertView.setBackgroundColor(getResources().getColor(
R.color.selectedvalues));
} else {
convertView
.setBackgroundResource((position % 2) == 0 ? R.color.light
: R.color.dark);
}
holder = (ViewHolder) convertView.getTag();
}
holder.txtProduct.setText((this.getItem(position)
.get("description").toString()));
holder.txtCode.setText((this.getItem(position).get("quantity")
.toString()));
return convertView;
}
}
當我從列表中選擇一個項目時,它的背景顏色被設置。但是當我們滾動列表時選定的背景顏色消失。 –