weixin_43244570
weixin_43244570
2019-01-18 10:48

Android中map最后一行数据覆盖问题,为什么显示的都是map中最后一对数据?

  • android-studio
  • android

图片说明

 public View getView(int position, View convertView, ViewGroup parent) {
        Drawing drawing = (Drawing) this.getItem(position);
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item, null);

            viewHolder.tv1 = (TextView) convertView.findViewById(R.id.tv1);
            viewHolder.tv2 = (EditText) convertView.findViewById(R.id.tv2);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        for (Map.Entry<String,Object> entry:map.entrySet()){
            String key=entry.getKey();
            String value=String.valueOf(entry.getValue());
            Log.d(TAG, "getView: "+key+"==="+value);
            viewHolder.tv1.setText(key);
            viewHolder.tv2.setText(value);
        }
        return convertView;
    }

想要的是将map中所有的key-value显示在listview中,但是最后全被map中的最后一行数据给覆盖了,如何才能显示出map中的每一对数据在listview中

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答