我目前正在開發一個Android應用程序。我希望屏幕左側有一個GridView,屏幕右側有一個MapView(假定佈局是橫向的)。 GridView將包含當前在SD卡上的照片,當選中時,exif標籤將被提取,並且如果有GPS信息,則將在地圖視圖上進行定位。顯示mapview片段旁邊的gridview片段,從SD卡加載圖像
我目前使用inazaruk的Map Fragment Example來顯示地圖片段。
我正在擴展Fragment並在我的網格片段類中實現LoaderManager.Callbacks。但是,「getLoaderManager()。initLoader」方法顯示錯誤 - 表示PhotoGridFragment類不適用。
爲PhotoGridFragment當前的代碼是:
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);
}
我很清楚我走錯了地方與該片的初始化,但我不能完全肯定在哪裏。如果需要,可以編輯以爲應用程序的其餘部分提供代碼。
基本上我想知道:爲什麼這個代碼不工作?我的方法是從SD卡中檢索圖像是否正確?或者那是錯的?