我在列表中设置了多个值,列表视图项包含按钮和名称。选择列表中的项目以更改颜色,如果我滚动列表项目,则删除选择。
代码
@Override
public View getGroupView(final int i, boolean b, View view, ViewGroup viewGroup) {
final GroupViewHolder groupViewHolder;
if(view==null) {
groupViewHolder=new GroupViewHolder();
view=((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.product_listview_group_item,null);
groupViewHolder.name=(TextView)view.findViewById(R.id.category_listview_item_name);
groupViewHolder.price = (TextView)view.findViewById(R.id.category_listview_item_price);
groupViewHolder.nameIcon=(ImageView)view.findViewById(R.id.category_listview_item_icon);
groupViewHolder.onClick=(ImageButton)view.findViewById(R.id.category_listview_item_onclick);
view.setTag(groupViewHolder);
} else {
groupViewHolder=(GroupViewHolder)view.getTag();
}
groupViewHolder.nameIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (groupViewHolder.nameIcon.getTag() == null) { groupViewHolder.name.setTextColor(Color.parseColor("#ffc400")); groupViewHolder.price.setTextColor(Color.parseColor("#ffc400")); groupViewHolder.nameIcon.setBackgroundResource(R.mipmap.yellow_circle_list_item); groupViewHolder.nameIcon.setTag(R.mipmap.yellow_circle_list_item);
dataHandler.addTempproducts(datas.get(i));
} else { groupViewHolder.nameIcon.setBackgroundResource(R.mipmap.black_circle_list_item); groupViewHolder.name.setTextColor(Color.parseColor("#ffffff")); groupViewHolder.price.setTextColor(Color.parseColor("#ffffff"));
groupViewHolder.nameIcon.setTag(null);
dataHandler.removeTempProducts(datas.get(i));
}
}
});
if(datas.get(i).getPrice().isEmpty()) {
groupViewHolder.price.setText(datas.get(i).getPrice());
} else {
groupViewHolder.price.setText(datas.get(i).getPrice() + "/-");
}
groupViewHolder.name.setText(datas.get(i).getName());
return view;
}