0

두 개의 조각 클래스를 만드는 마스터 클래스가 있습니다. 그중 하나가 MapDisplay()입니다.이 클래스에지도를 표시하고 싶습니다. 여기 내 XML 레이아웃 파일은 내가 원하는지도를 표시하지 않습니다, 조각 내지도 표시

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <fragment 
     android:id="@+id/map2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.MapFragment" /> 



</RelativeLayout> 

그러나이 클래스

을 maplayout 것 MapDisplay에 대한 내 코드() 여기

public class MapDisplay extends Fragment implements OnMapClickListener{ 
    private GoogleMap googlemap; 
    LatLng GAN = new LatLng(34.4305556,74.9250000); 

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

     View rootView = inflater.inflate(R.layout.maplayout, container, false); 


     try 
     { 
      if(googlemap==null) 
      { 
       googlemap= 
      ((SupportMapFragment)getFragmentManager().findFragmentById(R.id.map2)).getMap(); 
      googlemap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
      googlemap.setMyLocationEnabled(true); 
      googlemap.getUiSettings().setMyLocationButtonEnabled(true); 
      googlemap.getUiSettings().setZoomControlsEnabled(false); 

      } 
      if(googlemap!=null) 
      { 

      Marker m = googlemap.addMarker(new MarkerOptions().position(GAN).title("Gangbal")); 
      m.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)); 
      googlemap.moveCamera(CameraUpdateFactory.newLatLngZoom(GAN, 15)); 
      googlemap.animateCamera(CameraUpdateFactory.zoomTo(10),2000,null); 
      googlemap.setOnMapClickListener(this); 
      } 
      else 
      { 
       Toast.makeText(getActivity(), "WELL! HELLO THERE", Toast.LENGTH_LONG).show(); 
      }  
     } catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 
     return rootView; 
    } 

    @Override 
    public void onMapClick(LatLng arg0) { 
     Bundle args1 = new Bundle(); 
     args1.putParcelable("LOCATION", GAN); 
     Intent a = new Intent(getActivity(),FullScreenMap.class); 
     a.putExtra("bundle", args1); 
     a.putExtra("title", "Gangbal"); 
     startActivity(a); 

    } 
} 

그리고이다. 마커가없는 세계지도. 이지도를 클릭해도 작동하지 않습니다.

내가 다른 클래스

FragmentPagerAdapter tabadapter = new TabAdapter(getSupportFragmentManager()); 
ViewPager pager = (ViewPager)findViewById(R.id.tabpager); 
pager.setAdapter(tabadapter); 

    class TabAdapter extends FragmentPagerAdapter{ 
public TabAdapter(FragmentManager fm){ 
    super(fm); 
} 

@Override 
    public Fragment getItem(int m) { 
    switch(m) 
    { 
    case 0: 
     return new MapDisplay(); 
    case 1: 
     return new Description(); 
    } 
    return null; 
} 

    @Override 
    public CharSequence getPageTitle(int position) { 
     return CONTENT[position % CONTENT.length]; 
    } 

    @Override 
    public int getCount() { 
     return CONTENT.length; 
    } 

}

그래서 내가 MapDisplay()가 조각을 확장해야 추측에 MapDisplay() 조각 클래스를 만드는거야, 바로? 내가 뭘 잘못하고 있니? 도와주세요!

+0

당신이 MapFragment가 대신 조각을 확장하는 시도 해 봤나 @ 답을 확인할 수 있습니까? –

+0

완전히 잘못하고 있습니다.'Fragment' 대신'MapFragment'를 확장해야하며, XML에서'MapFragment'를 사용할 때'SupportMapFragment'를 사용해서는 안되며, id에 의한 Fragment를 얻지 못합니다. 단편, 당신은 오직 활동에서 그것을한다 – tyczj

+0

@tyczj. 편집 된 질문을 확인하십시오. 나는 조각 클래스를 만들고있다. – user1377504

답변

0

MapView을 사용해야하거나 조각이 MapFragment이어야합니다.

http://developer.android.com/reference/com/google/android/gms/maps/MapView.html

그래서 당신은 또한 구글의 가용성이 여기에 표시되지 않은 서비스를 재생 확인해야 조각

View rootView = inflater.inflate(R.layout.maplayout, container, false); 
MapView mapView = (MapView) rootView.findViewById(R.id.map); 
GoogleMap map = mapView.getMap(); 

에서 maplayout.xml

<?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" > 

<com.google.android.gms.maps.MapView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/map" 
    /> 

</RelativeLayout> 

의 아래에있다.

참고 :이 클래스 (지도보기)의

사용자는이 클래스에 해당하는 사람이보기가 포함 Activity 또는 Fragment로부터 모든 라이프 사이클 메소드를 전달해야합니다. 특히, 다음 방법에 전달해야합니다 :

onCreate(Bundle) 
onResume() 
onPause() 
onDestroy() 
onSaveInstanceState() 
onLowMemory() 

당신은

Android - android.view.InflateException: Binary XML file line #8: Error inflating class fragment