我有一个listView和适配器:
resultAdapter = new SimpleCursorAdapter(getActivity(),
R.layout.custom_products_list, null, new String[] {
StoreData.Product.NAME,
StoreData.Product.PRICE,
StoreData.BrandRecord.NAME3 }, new int[] {
R.id.productItem, R.id.productPItem,
R.id.productBItem }, 0){
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
View viewGroup=super.getView(position, convertView, parent);
if (position % 2 == 0)
viewGroup.setBackgroundResource(color.even_row_color);
else
viewGroup.setBackgroundResource(android.R.color.background_light);
//viewGroup.setClickable(true);
return viewGroup;
}
};
这是制作两种颜色列表。一切正常,我有两种颜色的项目列表。但是,当我点击列表中的任何项目推动效果消失。当我点击我要改变颜色的项目时,我希望看到基本列表视图中的效果。我怎么能这样做?
答案 0 :(得分:1)
尝试对convertView
进行更改并将其返回:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=li.inflate(R.layout.custom_products_list, null);
}
if (position % 2 == 0)
convertView.setBackgroundResource(color.even_row_color);
else
convertView.setBackgroundResource(android.R.color.background_light);
return convertView;
}