0

在我的代码中按下相机按钮后onActivityResult调用(由于意图)。在这种方法中,我编写了将捕获的图像添加到listView. 我想要的是,当我第二次捕获图像时,第一个图像listView不应该消失。如果我已经拍摄了三次图像,那么应该有三个listview项目。每次捕获图像时,我的代码仅显示一项。我已经尝试了很多,但无法弄清楚。谢谢。

ArrayList<HashMap<String, Object>> hashMapListForListView=new ArrayList<HashMap<String,Object>>();     

protected void onActivityResult(int requestCode, int resultCode, Intent data) {



        super.onActivityResult(requestCode, resultCode, data);


        if(resultCode == Activity.RESULT_OK )
        {      
  if (requestCode == take_image) {

        //get image
              final Bitmap thumbnail = (Bitmap) data.getExtras().get("data");  

            Viewimage.setImageBitmap(thumbnail);

              Adapter=new SimpleAdapter(this,hashMapListForListView,R.layout.imageview2,new String[]{"image"}, new int[]{R.id.imageView2});


            HashMap<String, Object>temp11=new HashMap<String, Object>();
            //Drawable d = new BitmapDrawable(getResources(),thumbnail);
            temp11.put("image",thumbnail);

            hashMapListForListView.add(temp11);
            listviewattachment.setAdapter(Adapter);
            Adapter.setViewBinder(new MyViewBinder());
            Adapter.notifyDataSetChanged();
4

1 回答 1

0

发生这种情况只是因为您每次都在onActivityResult(). 第二件事是,不需要通过使用一次又一次地设置适配器,setAdapter()notifyDataSetChanged()只是必需的。

更新:

正如您在评论中所说,您想从列表中删除项目,请尝试:

Object toRemove = arrayAdapter.getItem([POSITION]);
arrayAdapter.remove(toRemove);
于 2013-10-01T20:19:10.713 回答