小应用2.(listview单个Item点击时防止其他的跟随变化)

在ListView的适配器(adpter)里加代码,并且防止复用所产生的重复

 HashMap Imap = new HashMap();
public View getView(int position, View convertView, ViewGroup parent) {
    viewholder holder=null;
    if (Imap.get(position)==null){
        convertView= LayoutInflater.from(parent.getContext()).inflate(R.layout.choose_pick_item,null);
        holder=new viewholder(convertView);
        final int p = position;
        Imap.put(position, convertView);
        convertView.setTag(holder);
    }else {
        convertView=Imap.get(position);
        holder= (viewholder) convertView.getTag();
    }
    final CustomEntity entity=data.get(position);
    holder.namenumber.setText(entity.getNamenumber());
    holder.data.setText(entity.getData());
    holder.location.setText(entity.getLoad());
    holder.tel.setText(entity.getTel());
    return holder.convertView;
}

你可能感兴趣的:(小应用2.(listview单个Item点击时防止其他的跟随变化))