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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:56:22+00:00 2026-06-10T11:56:22+00:00

Im trying to do this: protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  • 0

Im trying to do this:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        cursor.close();
        Bitmap bmp = BitmapFactory.decodeFile(picturePath);
        b[1].setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(bmp), null, null);
}

But it wont set the image, no matter what. I have tried several different methods too, like using an imagebutton instead of a button and using:

imageButton.setImageBitmap(bmp)

The gallery opens fine and and the callback comes to onActivityResult(…)
but the image wont appear on the button, I have an array of buttons.

  • 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-10T11:56:24+00:00Added an answer on June 10, 2026 at 11:56 am

    I made a rapid test. The following code works for me. If with this you still can’t set the image I would check if there’s a layout problem (i.e. the image is set but there’s no room to show it).

    activity_main.xml has just an ImageButton set to wrap_content, inside the main layout which is match_parent.

    public class MainActivity extends Activity {
    
        ImageButton imgButton;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            imgButton = (ImageButton) findViewById(R.id.imgButton);
    
            imgButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Intent.ACTION_PICK);
                    intent.setType("image/*");
    
                    startActivityForResult(intent, 0);
                }
            });
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            if(requestCode == RESULT_CANCELED) return;
    
            ParcelFileDescriptor fd;
            try {
                fd = getContentResolver().openFileDescriptor(data.getData(), "r");
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return;
            }
    
            Bitmap bmp = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
    
            imgButton.setImageBitmap(bmp);
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fetch the IP address using this:- protected void Page_Load(object sender,
In C# I can test for this... public event EventHandler Trigger; protected void OnTrigger(EventArgs
I'm trying to take a picture from the Camera using intent with onActivityResult but
This is how my Application_Start looks: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); _container.Register(Component.For<IWindsorContainer>()
After trying this simple console input with 5, the result is shown as 53
Im trying this, but when i press it it dont changes, it only displays
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I am trying this import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream;
I've being trying this for about 5 hours already, and I'm feeling really, really
I've been trying this from a long time. I'm having today's date and I

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.