【问题标题】:Delete an Image from ImageView Android从 Android ImageView 中删除图像
【发布时间】:2015-02-18 15:14:54
【问题描述】:

我从数据库中提取图像路径并创建一个 ImageView,然后将其添加到另一个包含所有图像的 ImageView。

 LinearLayout linearContainer = (LinearLayout) findViewById(R.id.linearContainer);
 ImageView imageViews = new LinearLayout(getApplicationContext());
 linearContainer.addView(imageViews);

 for all images
    Bitmap myBitmap = ThumbnailUtils.extractThumbnail(
            BitmapFactory.decodeFile(path), THUMBSIZE,
            THUMBSIZE);

    ImageView image = new ImageView(getApplicationContext());
    image.setImageBitmap(myBitmap);
    imageViews.addView(image);
    image.setPadding(10, 10, 10, 10);
 end

我为 ImageView 图像编写了一个点击监听器,它允许它编辑或删除。

 imageViews.setOnClickListener() {
     AlertDialog.Builder alert = new AlertDialog.Builder(FirstActivity.this);
     // alert has two buttons: edit & delete
     // Edit choice click listener
     // Delete choice click listener
 }

我需要知道路径才能从数据库中删除记录。但我没有得到关于添加“imageViews”实例的图像的任何信息。如何编写删除点击监听器?或者有没有其他更简单的方法来建立它?

【问题讨论】:

  • 我只想在你的模型中有一个属性 imageId 以便每个图像都有它,然后根据该 id 删除它

标签: android imageview android-imageview android-image


【解决方案1】:

imageview.setTag(path)中设置图片路径

并使用检索它

imageview.getTag()

【讨论】:

  • 我使用 imageView 创建所有图像并将它们全部添加到 imageViews 对象。例如:ImageView imageViews; ImageView imageView1 = "first image"; ImageView imageView2 = "first image"; ImageView imageView3 = "first image"; ImageView imageView4 = "first image"; imageViews.addView(imageView1); imageViews.addView(imageView2); imageViews.addView(imageView3); imageViews.addView(imageView4); linearLayout.addView(imageViews); then... imageViews.setOnClickListener() { // if i try to get the tag here it returns null }
猜你喜欢
  • 2011-10-02
  • 2016-08-29
  • 1970-01-01
  • 2014-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多