我試圖在片段的onActivityCreated中的一個relativeLayout中添加MapView(org.osmdroid.views.MapView)。但它不起作用。這個片段由ShrlockFragmentActivity啓動。 如何讓它工作?Mapview osmdroid在片段中不可見
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);
}