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

The Archive Base Latest Questions

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

i got problem with my code , i am trying to get image from

  • 0

i got problem with my code , i am trying to get image from the gallery and show it on my xml layout (The problem is when i click on the button it goes to the gallery but when i select a picture it just gees to another tab )

1) my main class which creates the tabs

public class MainUser extends TabActivit 
  .....

TabSpec tabSpec10 = mTabHost.newTabSpec("tab_test1");
        tabSpec10.setIndicator("Report incident ");
        Context ctx10 = this.getApplicationContext();
        Intent i10 = new Intent(ctx10, ucrimereport.class);
        tabSpec10.setContent(i10);
        mTabHost.addTab(tabSpec10);

2) this is the class where i am making and calling the gallery

public class ucrimereport extends Activity implements OnClickListener,OnItemSelectedListener {
    private static final int IMAGE = 1;

@Override   

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ureport);
.........
         gallary = (ImageButton)findViewById(R.id.sdpic_button);

gallary.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // gallary
            Intent gallery = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
            startActivityForResult(gallery, IMAGE);

        }
    });

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

      if(resultCode==RESULT_OK && requestCode==IMAGE){
       Uri selectedImage=data.getData();
       String path=getPath(selectedImage);

       Bitmap bitmapImage=BitmapFactory.decodeFile(path);
       //ImageView image=(ImageView)findViewById(R.id.image);
       image.setImageBitmap(bitmapImage);

      }
    }

    public String getPath(Uri uri){
      String[] filePathColumn={MediaStore.Images.Media.DATA};

      Cursor cursor=getContentResolver().query(uri, filePathColumn, null, null, null);
      cursor.moveToFirst();
      int columnIndex=cursor.getColumnIndex(filePathColumn[0]);

      return cursor.getString(columnIndex);
    }
  • 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-10T23:22:33+00:00Added an answer on June 10, 2026 at 11:22 pm

    Please Try that code .

    public class ImageGalleryDemoActivity extends Activity {    
        private static int RESULT_LOAD_IMAGE = 1;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
            buttonLoadImage.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View arg0) {
    
                    Intent i = new Intent(
                            Intent.ACTION_PICK,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    
                    startActivityForResult(i, RESULT_LOAD_IMAGE);
                }
            });
        } 
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            if (requestCode == RESULT_LOAD_IMAGE && 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();
    
                ImageView imageView = (ImageView) findViewById(R.id.imgView);
                imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn from google code and I got stuck in some problems.
I have the following code, but i got a problem. Within my While, a
Hey I got a problem here. I'm trying to retrieve the date from the
I got this problem trying to get the header-bg div to always be the
I have a problem trying to get my head around using UTF8 with Poco::XML::XMLWriter
i got problem with my code and hopefully someone able to figure it out.
So I've got a problem with my code and it's driving me nuts since
I want to ask about strcpy. I got problem here. Here is my code:
I got a problem when analyzing my code below : NSDate *formatterDate = [inputFormatter
Got a problem with my add function to my database. The following code hangs

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.