listview 长按时为什么只能显示一个checkbox
public class OrderShowAdater extends BaseAdapter {
private List<? extends Map<String, Object>> list;
private LayoutInflater inflater
private HashMap<Integer, View> mView;
// public HashMap<Integer, Integer> visiblecheck;// 用来记录是否显示checkBox
public HashMap<Integer, Boolean> ischeck;
private HashMap<Integer, CheckBox> boxes;
public OrderShowAdater(Context context, List<? extends Map<String, Object>> list) {
this.list = list;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = new HashMap<Integer, View>();
ischeck = new HashMap<Integer, Boolean>();
boxes = new HashMap<Integer, CheckBox>();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
AdapterHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listfor_order_show, null);
holder = new AdapterHolder(convertView);
boxes.put(position, holder.check);
ischeck.put(position, false);
mView.put(position, convertView);
convertView.setTag(holder);
//checkbox勾选监听
holder.check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
ischeck.put(position, isChecked);
}else{
ischeck.remove(position);
}
}
});
convertView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// if(mPullDownView.getMIsRefreshing()){
// return true;
// }
showCheckBoxes();
return true;
}
});
}else{
holder = (AdapterHolder) convertView.getTag();
}
holder.title.setText(list.get(position).get("title").toString());
holder.content.setText(list.get(position).get("content").toString());
holder.date.setText(list.get(position).get("date").toString());
return convertView;
}
private static class AdapterHolder{
TextView title;
TextView content;
TextView date;
CheckBox check;
public AdapterHolder(View view){
this.title = (TextView) view.findViewById(R.id.ordertitle);
this.check = (CheckBox) view.findViewById(R.id.orderinfocheckbox);
this.date = (TextView) view.findViewById(R.id.orderdate);
this.content = (TextView) view.findViewById(R.id.ordercontent);
}
}
/**
* 显示所有checkbox
*/
private void showCheckBoxes(){
for (int i = 0; i < boxes.size(); i++) {
boxes.get(i).setVisibility(View.VISIBLE);
}
}
// public void setIsMulChoice(boolean isMulChoice){
// this.isMulChoice = isMulChoice;
// }
public Map<Integer, CheckBox> getCheckBoxes(){
return this.boxes;
}
}
public class OrderShowAdater extends BaseAdapter {
private List<? extends Map<String, Object>> list;
private LayoutInflater inflater
private HashMap<Integer, View> mView;
// public HashMap<Integer, Integer> visiblecheck;// 用来记录是否显示checkBox
public HashMap<Integer, Boolean> ischeck;
private HashMap<Integer, CheckBox> boxes;
public OrderShowAdater(Context context, List<? extends Map<String, Object>> list) {
this.list = list;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = new HashMap<Integer, View>();
ischeck = new HashMap<Integer, Boolean>();
boxes = new HashMap<Integer, CheckBox>();
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
AdapterHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listfor_order_show, null);
holder = new AdapterHolder(convertView);
boxes.put(position, holder.check);
ischeck.put(position, false);
mView.put(position, convertView);
convertView.setTag(holder);
//checkbox勾选监听
holder.check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
ischeck.put(position, isChecked);
}else{
ischeck.remove(position);
}
}
});
convertView.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// if(mPullDownView.getMIsRefreshing()){
// return true;
// }
showCheckBoxes();
return true;
}
});
}else{
holder = (AdapterHolder) convertView.getTag();
}
holder.title.setText(list.get(position).get("title").toString());
holder.content.setText(list.get(position).get("content").toString());
holder.date.setText(list.get(position).get("date").toString());
return convertView;
}
private static class AdapterHolder{
TextView title;
TextView content;
TextView date;
CheckBox check;
public AdapterHolder(View view){
this.title = (TextView) view.findViewById(R.id.ordertitle);
this.check = (CheckBox) view.findViewById(R.id.orderinfocheckbox);
this.date = (TextView) view.findViewById(R.id.orderdate);
this.content = (TextView) view.findViewById(R.id.ordercontent);
}
}
/**
* 显示所有checkbox
*/
private void showCheckBoxes(){
for (int i = 0; i < boxes.size(); i++) {
boxes.get(i).setVisibility(View.VISIBLE);
}
}
// public void setIsMulChoice(boolean isMulChoice){
// this.isMulChoice = isMulChoice;
// }
public Map<Integer, CheckBox> getCheckBoxes(){
return this.boxes;
}
}