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 7804137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:48:57+00:00 2026-06-02T01:48:57+00:00

I currently have 2 classes named ProjectPreview and ImageAdapter. Projectpreview has the view along

  • 0

I currently have 2 classes named ProjectPreview and ImageAdapter.

Projectpreview has the view along with the actionbar.

I can’t figure out a way to get the ID of the current image within the imageview to the delete on the action bar.

oncreate in projectpreview:

    Gallery gallery = (Gallery) findViewById(R.id.gallery);
    gallery.setAdapter(new ImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            ImageAdapter ia1 = new ImageAdapter();
            ia1.showLarger(position); }

Delete code in projectpreview:

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_delete:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

ImageAdapter class:

     public Integer[] mImageIds = {
            R.drawable.sample_1,
            R.drawable.sample_2,
            R.drawable.sample_3,
            R.drawable.sample_4,
            R.drawable.sample_5,
            R.drawable.sample_6,
            R.drawable.sample_7
    };

    public void showLarger(int position){
        ImageView image = (ImageView) findViewById(R.id.iv1);
        image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        image.setImageResource(mImageIds[position]);
    }

I need to figure out a way to get the image.setImageResource(mImageIds[position]); to the other class so that I could remove the mImageIds[position] aka the picture.

  • 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-02T01:48:59+00:00Added an answer on June 2, 2026 at 1:48 am

    To do this you can use the setTag function on your ImageView. The tag can any type of object you want such as the id used for the image resource. When you want to remove it you can use imageView.getTag() which will return you the object you had set with setTag. I see that your delete code is running when a menu item is clicked. I don’t see a reference to the ImageView there so you will need to run a findViewById to get a reference to the view.

    Set the id:

    public void showLarger(int position){
        ImageView image = (ImageView) findViewById(R.id.iv1);
        image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        image.setImageResource(mImageIds[position]);
        image.setTag(mImageIds[position]);
    }
    

    Get the id:

        ImageView image = (ImageView) findViewById(R.id.iv1);
        int id = (Integer)image.getTag();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have service classes that look something like this public class UserService :
I currently have three classes User , UserProfile , and Vendor . User is
I have four classes which share some arrangement of four properties. I have currently
I currently have 2 concrete methods in 2 abstract classes. One class contains the
I have custom classes that I currently instantiate within App.xaml as resources. I want
Currently I have a DataModel object which contains my linq to sql classes(a dmbl
I'm currently using the hilo id generator for my classes but have just been
I'm currently using QDataStream to serialize my classes. I have quite a few number
Currently, I have a database access class named DB , which uses PDO .
I'm currently writing a serialization module in Python that can serialize user defined classes.

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.