public static class Mainfragment extends Fragment implements OnClickListener, OnDateSetListener, OnTimeSetListener {
int actionTabIndex;
int layout;
LatLng position;
GoogleMap googleMap;
Marker mkPumps;
LatLng pumpPos;
Marker[] markers;
static View v;
int buttonId;
public static Mainfragment makeObject(int actionTabIndex) {
Mainfragment bf = new Mainfragment();
bf.actionTabIndex = actionTabIndex;
return bf;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState) {
switch (actionTabIndex) {
case 0: layout = R.layout.framemap; break;
case 1: layout = R.layout.pmd; break;
case 2: layout = R.layout.maintenance; break;
case 3: layout = R.layout.report; break;
case 4: layout = R.layout.setting; break;
}
try{
v = inflater.inflate(layout, container, false);
}
catch (InflateException e) {
}
if (actionTabIndex == 0) initMap(); // GoogleMap
else if (actionTabIndex == 2) { // Maintenance
}
else if (actionTabIndex == 3) { // Report
}
return v;
}
private void initMap() {
try {
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity());
googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.googleMap)).getMap();
Pos = new LatLng(35.470707,128.65134);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(pumpPos, 15));
MarkerOptions moOption = new MarkerOptions();
moOption.position(Pos);
moOption.title("#1");
mkPumps = googleMap.addMarker(moOption);
mkPumps.showInfoWindow();
catch (Exception e) {
System.out.println(e.getMessage());
}
}
@Override
public void onDestroy() {
super.onDestroyView();
ViewGroup parent = (ViewGroup)v.getParent();
if(parent!=null){
parent.removeView(v);
}
}
}
앱을 실행하면 처음엔 구글 맵의 프레그먼트가 생성됩니다.
액션바를 클릭할 때마다 같은 프레그먼트, 다른 레이아웃 -> 프레임레이아웃에 생성됩니다.
다른 탭들은 모두 실행이 잘 되는데 다시 구글맵을 띄우면 보이지가 않네요 ㅜ