在按下相机按钮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();
答案 0 :(得分:0)
这是因为您每次都在onActivityResult()
创建适配器。第二件事是,不需要使用setAdapter()
一次又一次地设置适配器,但只需要notifyDataSetChanged()
。
<强>更新强>
正如您在评论中所说,您想要从列表中删除项目,请尝试:
Object toRemove = arrayAdapter.getItem([POSITION]);
arrayAdapter.remove(toRemove);