2013-12-19 2 views
0

DialogFragment 안에 MapFragment를 넣으려고해도 잘 작동하지만 getMap()까지 기다릴 수있는 방법을 모르겠다! : null ... 여기 내 코드 :안드로이드 : GetMap() == null DialogFragment

public class DialogMapa extends DialogFragment{ 

    private SupportMapFragment fragment; 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.layout_dialog_mapa, container,false); 
     getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); 

     SupportMapFragment fragment = new SupportMapFragment(); 
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
     transaction.add(R.id.map, fragment).commit();  

     GoogleMap mapa = null; 
     try { 
      mapa =fragment.getMap(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     if (mapa==null) Toast.makeText(getActivity(), "NULL", Toast.LENGTH_SHORT).show(); 


    return view; 
    } 

} 

내 부풀려 레이아웃 : 미리

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="0dp" > 

    <FrameLayout 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </FrameLayout> 

</RelativeLayout> 

감사합니다!

답변

1

새 맵 프레임 워크에서이 호출은 null이 아닌 값을 반환하지 않을 수 있습니다. 지도는 꽤 복잡하고 렌더링 스레드에서 많은 상태를 초기화하고 있습니다.

onFragmentsResumed() 이후 또는 해당 프래그먼트가 활동에 첨부 된 후에는 안전합니다. 나중에 언제든지 다시 처리기를 사용하여 다시 확인할 수 있습니다.

+0

작동합니다. tyvm ^^ – naxo

0

뷰 생성 후 대화 조각의 onStart() 내에서 getMap()이 null이 아닙니다.