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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:52:26+00:00 2026-06-05T02:52:26+00:00

I’ve got three tabs, a map, an image gallery, and a settings tag. I’ve

  • 0

I’ve got three tabs, a map, an image gallery, and a settings tag. I’ve tried to set them up using fragments and they work for the most part. To get the map tab working, I followed this guy’s stuff MapView in a Fragment (Honeycomb).

The settings tab uses a ListFragment and works fine, as does the map. The image tab I have works right the first time also. I navigate to it, and all the images load up correctly, but if I switch to one of the other tabs and come back to the images tab, everything’s gone and nothing loads. The images tab will load correctly if I back out of the app and open it up again, which makes me think something is getting loaded right, but not being reinitialized or something when I navigate to that tab.

Image gallery code:

public class ImageGridFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> {

ImageAdapter imageAdapter;
GalleryItem[] galleryItems = new GalleryItem[0];
GridView gridView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    getActivity().getSupportLoaderManager().initLoader(0, null, this);
    imageAdapter = new ImageAdapter(getActivity(), galleryItems);
}

@Override
public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.image_grid_fragment, container, false);
    gridView = (GridView) v.findViewById(R.id.gridView);
    Gallery.setContentResolver(getActivity().getContentResolver());
    Gallery.setDefaultBitmap(getResources(), R.drawable.loading);
    gridView.setOnItemClickListener(new GridView.OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, final int position, long id) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            final LayoutInflater
                    inflater = (LayoutInflater) getActivity().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.image_popup, null);
            ImageView image = (ImageView) view.findViewById(R.id.image);
            Drawable d = Drawable.createFromPath(galleryItems[position].getUri().getPath());
            image.setImageDrawable(d);
            image.setMinimumHeight(d.getMinimumHeight());// (int) (d.getIntrinsicHeight() * 2.5));
            image.setMinimumWidth(d.getIntrinsicWidth());// (int) (d.getIntrinsicWidth() * 2.5));
            builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent sendIntent = new Intent(getActivity(), RecordSomething.class);
                    sendIntent.putExtra("FILE", new File(galleryItems[position].getUri().getPath()));
                    startActivityForResult(sendIntent, Constants.ACTIVITY_SEND_PHOTO);
                }
            });
            builder.setNegativeButton("Cancel", null);
            builder.setView(view);
            builder.show();
        }
    });
    return v;
}

/* Creates the menu items */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.gallery_menu, menu);
    super.onCreateOptionsMenu(menu, inflater);
}

/* Handles item selections */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_camera:
            Intent camIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            /*
             * The below code was used to send a parameter to the native camera app to tell it
             * to save a copy of the image taken to the file we specified. This worked fine,
             * except that the image lost it's orientation. What we do instead is in onActivityResult
             * we find the most recent image taken, move it to our folder, rename it, and resize it
             */

            startActivityForResult(camIntent, Constants.ACTIVITY_TAKE_PHOTO);
            return true;
    }
    return false;
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case Constants.ACTIVITY_TAKE_PHOTO:
            if (resultCode == Activity.RESULT_OK) {
                Intent sendIntent = new Intent(getActivity(), RecordSomething.class);
                sendIntent.putExtra("FILE", "test"); //TODO get the path from the array of pictures
                startActivityForResult(sendIntent, Constants.ACTIVITY_SEND_PHOTO);
            }
            break;
    }
}

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    return new CursorLoader(getActivity(),
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[]{
                    MediaStore.Images.ImageColumns._ID,
                    MediaStore.Images.ImageColumns.ORIENTATION,
                    MediaStore.Images.Media.DATA
            },
            MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME + " = 'Camera'",
            null,
            MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");
}

@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
    galleryItems = new GalleryItem[cursor.getCount()];

    cursor.moveToFirst();
    if (cursor.moveToFirst()) {
        int i = 0;
        do {
            galleryItems[i] = new GalleryItem(
                    cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID)),
                    cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)),
                    cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns.ORIENTATION)));
            i++;
        } while (cursor.moveToNext());
    }

    imageAdapter.setGalleryItems(galleryItems);
    gridView.setAdapter(imageAdapter);
}

@Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {}
}

any help, much appreciated

  • 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-05T02:52:28+00:00Added an answer on June 5, 2026 at 2:52 am

    In case anyone’s curious, I solved it. Problem was I wasn’t calling gridView.setAdapter in onCreateView. The reason everything worked the first time was because that’s when the cursor was loaded, so it was called in onLoadFinished, as you can see above.

    I needed to put it onCreateView because my gridview is redefined there everytime, so if I don’t call setAdapter and the cursor has already loaded. The pictures don’t begin to populate.

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters

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.