2017-03-24 5 views
0

와 나는이 작업과 함께 일하고 있어요 :안드로이드에서 getSupportFragmentManager는 FragmentActivity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/activity_view" 
    > 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/tlbMenuView" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     android:elevation="4dp" 
     /> 

    <FrameLayout 
     android:id="@+id/activity_fragment_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 
</LinearLayout> 
: 활동의 존재에 대한 간단한 레이아웃으로

public class ViatgeDetallViewFragment extends FragmentActivity implements OnMapReadyCallback { 

    public ViatgeDetallViewFragment() { 
    } 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

    } 


    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_view, container, false); 


     SupportMapFragment mapFragment = 
       (SupportMapFragment) 
         getSupportFragmentManager() 
           .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 


     return rootView; 
    } 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     ... 

} 

:

public class ViatgeDetallViewActivity extends AppCompatActivity { 

    ViatgeDetallViewFragment fragment; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_view); 


      fragment = new ViatgeDetallViewFragment();   
      getSupportFragmentManager().beginTransaction() 
        .add(R.id.activity_fragment_view, fragment) 
        .commit(); 


     } 
    ..... 
    } 

클래스 ViatgeDetallViewFragment이있다

그리고 fragment_view :

나는 그러나 똑같은 코드를 시도했습니다

Error:(68, 21) error: no suitable method found for add(int,ViatgeDetallViewFragment) 
method FragmentTransaction.add(Fragment,String) is not applicable 
(argument mismatch; int cannot be converted to Fragment) 
method FragmentTransaction.add(int,Fragment) is not applicable 
(argument mismatch; ViatgeDetallViewFragment cannot be converted to Fragment) 

: 나는 다음과 같은 오류가

fragment = new ViatgeDetallViewFragment();   
      getSupportFragmentManager().beginTransaction() 
        .add(R.id.activity_fragment_view, fragment) 
        .commit(); 

: 내가 조각을 추가 할 때 10

<LinearLayout android:id="@+id/layout_fragment_view" xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="View" 
     />  
    <fragment 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/fragment_view_map" 
     class="com.google.android.gms.maps.MapFragment"></fragment> 

</LinearLayout> 

문제는 "ViatgeDetallViewActivity"에 온다 "FragmentActivity"가 아닌 "fragment"를 확장하는 프래그먼트 클래스가 있고 모든 것이 잘되었다.

+0

; mapFragment.getMapAsync (this); 구글 맵으로 작업 할 필요가 없으므로 FragmentActivity 클래스를 확장해야합니다. – Asdemuertes

+0

변경 사항을 적용한 ViatgeDetallViewFragment가 조각을 확장하고 레이아웃에 supportMapfragment가 대신 있습니다. 작동하지 않는 것 같습니다. 이전과 같은 문제 + "SupportMapFragment"를 얻으려고 할 때 ViatgeDetallViewFragment의 새로운 오류 – Asdemuertes

+0

작동하는 것 같습니다! 사실, 가져 오기를 변경하면 오류가 해결되었습니다! – Asdemuertes

답변

0

조각 FragmentActivity 대신 조각을 확장해야합니다. 내가 다음 줄 SupportMapFragment으로 MapFragment = (SupportMapFragment) 에서 getSupportFragmentManager() .findFragmentById (R.id.map) 문제를 얻을 것이라고 할 위치를 경우