2013-10-01 36 views
0

在我的代码后按下相机按钮onActivityResult调用(作为意图的结果)。在这种方法中,我已经编写代码在listView中添加捕获的图像。我想要的是,当我第二次拍摄图像时,listView中的第一张图像不应该消失。如果我拍摄了三次图像,则应该有三个listview项目。我的代码每次捕捉图像时只显示一个项目。我已经尝试了很多,无法弄清楚。 谢谢。追加摄像机图像在列表框中的ANdroid

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(); 

回答

0

它的发生只是因为你在onActivityResult()创建适配器每次。第二件事是,不需要通过使用setAdapter()来一次又一次地设置适配器,但仅需要notifyDataSetChanged()

更新:

正如你在评论说,你想删除列表项,请尝试:

Object toRemove = arrayAdapter.getItem([POSITION]); 
arrayAdapter.remove(toRemove); 
+0

感谢帕雷什..它是working..can你告诉我怎样可以删除任何我不喜欢列表中的项目? – user2768215