Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:07:25+00:00 2026-06-01T04:07:25+00:00

I am trying to create a delete button over each image that appears in

  • 0

I am trying to create a delete button over each image that appears in a gallery. but when the delete button is pressed on any given image it shows the same uri instead of the one of the image it is holding..
my image adapter:

public class GallImageAdapter extends BaseAdapter {
    public Cursor cursor;
    private int columnIndex;
    private Context context;
    int imageBackground;
    String url;
    Uri uri;
    int originalImageId;
    int imageID;
    int columnData;
    ViewGroup myp;

    public GallImageAdapter(Context ctx, Cursor cur, int cIn ) {
        context = ctx;
        columnIndex = cIn;

        cursor = cur;
    }

    @Override
    public int getCount() {

        return cursor.getCount();
    }

    @Override
    public Object getItem(int position) {

        return position;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        myp = parent;
        View v;
        if(convertView ==null){
            v = LayoutInflater.from(context).inflate(R.layout.galitem, parent, false);
        }else{
            v = convertView;
        }


        ImageView photo = (ImageView) v.findViewById(R.id.imageView);
        ImageView border = (ImageView) v.findViewById(R.id.borderView);
        ImageView d = (ImageView) v.findViewById(R.id.delView);



        // Move cursor to current position
        cursor.moveToPosition(position);

        // Get the current value for the requested column
        imageID = cursor.getInt(columnIndex);
        // obtain the image URI
        uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
        url = uri.toString();
        // Set the content of the image based on the image URI
        originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
        Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
                        originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
        photo.setImageBitmap(b);

        photo.setScaleType(ImageView.ScaleType.FIT_CENTER); 

        d.setOnClickListener(new OnClickListener(){

            public void onClick(View v) {
                // TODO Auto-generated method stub



                Toast.makeText(v.getContext(), "Delete: " + uri + "?", Toast.LENGTH_LONG).show();
                File file = new File(cursor.getString(columnIndex));
                boolean deleted = file.delete();
                //context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                  //       Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
            }


        });

        return v;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:07:26+00:00Added an answer on June 1, 2026 at 4:07 am

    Store the URI 0f the image in the tag of the button. Then retrieve it in the onClick.

    The problem with your current code is that uri is declared as a class level field so each time a view is retrieved, it’s value is set to the uri of the current image. Since all of your views are retrieved when your layout displays, the uri will always end up as the last view retrieved. You then access it some time later in the onClick handler – which is the same for every button. Thus, every button will access the same value of the uri.

    There are other, perhaps more elegant ways of achieving what you need but storing the uri in the button instance and getting it from the view passed to onClick, which is a button, is easy and simple – but do comment the setTag method call so that you’ll know what you did in 6 months time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a page that lets a user delete an image
I'm trying to create a simple button that deletes a row from the database.
I have a table that I am trying to dynamically delete rows from. Each
I'm trying to create a cron job which will automatically delete .jpg files from
I am trying create a WCF service that leverages the WPF MediaPlayer on the
Trying to create a user account in a test. But getting a Object reference
Trying to create my first iPhone app that would play back audio. When I
I'm trying to create a small web app that is used to remove items
Two questions. First question is I'm trying to create a simple form that when
I am trying to create a text input field that converts the input text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.