Pergunta

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?

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top