0

I'm currently working on an Android application. I wish to have a GridView on the left side of the screen, and a MapView on the right side of the screen (assumption that the layout is landscape). The GridView will contain the photos currently on the SD card, and when selected, the exif tags will be extracted and, if there is GPS information, that will be targeted on the Map View.

I'm currently using inazaruk's Map Fragment Example to display the map fragment.

I am extending Fragment and implementing LoaderManager.Callbacks within my grid fragment class. However, the "getLoaderManager().initLoader" method displays an error - saying that the PhotoGridFragment class is not applicable.

The current code for the PhotoGridFragment is:

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

// member variables for
private static final int PHOTO_LIST_LOADER = 0x01;
private SimpleCursorAdapter adapter;
private CursorLoader cursorLoader;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getLoaderManager().initLoader(PHOTO_LIST_LOADER, null, this);
    adapter = new SimpleCursorAdapter(
            getActivity().getApplicationContext(), R.layout.grid_item,
            null, new String[] { MediaStore.Images.Thumbnails.IMAGE_ID }, null,
            CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    return inflater.inflate(R.layout.grid_item, container, false);      
}



// Loader manager methods
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = { MediaStore.Images.Thumbnails._ID };
    CursorLoader cursorLoader = new CursorLoader(getActivity(),
            MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection,
            null, null, null);
    return cursorLoader;
}

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
}

public void onLoaderReset(Loader<Cursor> cursor) {
    adapter.swapCursor(null);
}

I clearly am going wrong somewhere with the initialisation of the Fragment, but I'm not entirely sure where. Can edit to give code for the rest of the application if need be.

Basically I want to know: why doesn't this code work? And is my method for retrieving images from the SD card correct? Or is that wrong as well?

1 Answer 1

0

This was solved. I was using the compatibility fragment classes (android.support.v4.app.Fragment, for example). The "initLoader" method does not take a compatibility fragment as a parameter. After changing to android.app.Fragment, this issue was solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.