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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:39:11+00:00 2026-06-13T11:39:11+00:00

I currently have a gridview that returns an images position/id to a parent activity.

  • 0

I currently have a gridview that returns an images position/id to a parent activity. I would also like to return or extract the images Uri to the parent activity and set it to a variable that can be parsed somewhere else in the parent activity. I’ve been looking for a bit but cant quite find a solution that fits what I’m attempting.

My gridview child activity that returns the position

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grid_layout);

    GridView gridView = (GridView) findViewById(R.id.grid_view);

    // Instance of ImageAdapter Class
    gridView.setAdapter(new ImageAdapter(this));

    /**
     * On Click event for Single Gridview Item
     * */
    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {


            Intent data = new Intent(PicPicker2.this, PictureActivity.class);
            // passing array index
            data.putExtra("id", position);
            setResult(Activity.RESULT_OK, data);
            finish();
        }
    });
}

}

Where I currently catch the result in the parent activity

            else if (reqCode == 2) {


                // Selected image id
                int position = data.getExtras().getInt("id");
                ImageAdapter imageAdapter = new ImageAdapter(this);
                ChosenImageView.setImageResource(imageAdapter.mThumbIds[position]);
              }
            }
        }     

Where I want to parse the variable

        Uri attached_Uri = Uri.parse("SOME VARIABLE OF THE RETURNED URI");

I want to set Uri attached_Uri = Uri.parse() to the item that was clicked in the gridview. I’m just a weekend Android tinkerer trying to learn the concepts of the platform so explanations and examples go a long way for me and are greatly appreciated.

Added my imageadapter

public class ImageAdapter extends BaseAdapter {

private Context mContext;


// Keep all Images in array
public Integer[] mThumbIds = {
        R.drawable.pic_1, R.drawable.pic_2,
        R.drawable.pic_3, R.drawable.pic_4,
        R.drawable.pic_5, R.drawable.pic_6,
        R.drawable.pic_7, R.drawable.pic_8,
        R.drawable.pic_9, R.drawable.pic_10,
        R.drawable.pic_11, R.drawable.pic_12,
        R.drawable.pic_13, R.drawable.pic_14,
        R.drawable.pic_15
};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return mThumbIds.length;
}

@Override
public Object getItem(int position) {
    return mThumbIds[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
    return imageView;
}

}

  • 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-13T11:39:12+00:00Added an answer on June 13, 2026 at 11:39 am

    You’re using resources as images, so the uris are of the form "android.resource://your.package.name/resource_id". To be more specific, lets say you have the index of the image in a variable position (as you would in the onClick method), and you’ve got an instance of ImageAdapter in mImageAdapter (note that in your case you could just create a new copy of the adapter, but generally you’d want to use a common instance). Then the following will get you your Uri

    Uri imageUri = Uri.parse("android.resource://your.package.name/" + 
         mImageAdapter.getItem(position));
    

    In the above code "your.package.name" is the name of the package as defined in your AndroidManifest.xml file.

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

Sidebar

Related Questions

I have a gridview that has a column that currently returns a 1 if
I currently have a Gridview that displays TypeID , Name , Description. I would
I currently have an asp:GridView that displays a few BoundFields and then one asp:TemplateField
Currently I have few methods that accept GridView object as parameter and the value
I currently have a gridview that is set up and working properly but I
I currently have a gridview that is populated via database through a c# method.
I currently have a control that called MyGridview that inherits Gridview. It has a
I currently have a gridview that has an asp:ButtonField as one of the columns.
I currently have a Gridview , And I want to use client-side validation to
Currently I have a DetailsView attached to a GridView. When you select an item

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.