0
public class PlaceMapsFragment extends SupportMapFragment { 
    private GoogleMap mMap; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     View v = inflater.inflate(R.layout.fragment_place_maps, container, 
       false); 


     setUpMapIfNeeded(); 
     return v; 
    } 

    private void setUpMapIfNeeded() { 
     if (mMap == null) { 
      mMap = ((MapView) findViewById(R.id.map)).getMap(); 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 

    private void setUpMap() { 
     mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title(
       "Marker")); 
    } 
} 

오류에 대한 정의되지안드로이드 [SupportMapFragment] 방법 findViewById를 (INT)이 유형

The method findViewById(int) is undefined for the type PlaceMapsFragment 

답변

2

내가 정확히 기억한다면, 모든 조각 네이티브 findViewById() 방법이 없습니다. 이것이 onCreateView() 메서드를 사용해야하는 이유입니다.

즉, setUpMapIfNeeded()setUpMapIfNeeded(View view)으로 변경하고 onCreateView()을 수정 된 방법으로 변경해야합니다. mMap = ((MapView) findViewById(R.id.map)).getMap();mMap = ((MapView) view.findViewById(R.id.map)).getMap();으로 변경해야합니다.

1

나는 당신이 SupportMapFragment 클래스를 서브 클래 싱 할 수 있습니다 모르겠어요.

SupportMapFragment.newInstance 호출 SupportMapFragment의 새로운 인스턴스를 얻으려면이 당신의 개체를 반환합니다.

서브 클래스를 호출하고 예를 들어 PlaceMapsFragment.newInstance()을 호출하면 SupportMapFragment 개체가 계속 반환됩니다.

프로그래밍 방식으로지도를 조작하려면

, 난 당신이 다음을 수행하는 것이 좋습니다.

this.mSupportMapFragment = SupportMapFragment.newInstance(); 
MapHandler mMapHandler = new mMapHandler(this.mSupportMapFragment.getMap()); 

희망이 있습니다.