我试图在 Fragment 的 onActivityCreated 的 relativeLayout 中添加 MapView (org.osmdroid.views.MapView)。但它不起作用。此 Fragment 由 ShrlockFragmentActivity 启动。我怎样才能让它工作?
public class CommuneFragment extends SherlockFragment {
Context mContext = getActivity();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState) ;
return inflater.inflate(R.layout.commune_map_fragment, container, false);
}
@Override
public void onActivityCreated(final Bundle savedState) {
super.onActivityCreated(savedState);
mContext=getActivity();
View mView = getView();
//Create the OSM view
MapView mapView = new MapView(mContext, null);
//enable zoom in and out on the OSM
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
RelativeLayout RL= (RelativeLayout) getActivity().findViewById(R.id.rl);
RL.addView(mapView);
}