2014-08-28 1 views
0

제 경우에는 한 조각에서 다른 조각으로 이동하고 싶습니다. 이 ListView 클릭 할 때 수행해야합니다. 그래서 onItemClick에 프래그먼트 트랜잭션 코드를 작성했습니다. 그러나 나는 어디에서 움직여야 할지를 알 수있는 컨테이너 ID를 찾는 방법을 모른다.Android : 조각 컨테이너 ID를 찾는 방법

여기 내 코드입니다.

lv.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      // TODO Auto-generated method stub 
      Fragment fragment = new MeetingFragment(); 
      FragmentManager fragmentManager = getActivity().getFragmentManager(); 
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
      fragmentTransaction.replace(R.id.MEETING, fragment); 
      fragmentTransaction.addToBackStack(null); 
      fragmentTransaction.commit(); 
     } 

    }); 

MeetingFragment로 이동하고 싶습니다. 이 프래그먼트에서 제공해야하는 이드입니다. 트랜잭션 (transaction) .replace (R.id. 아이디어를주십시오. 미리 감사드립니다.

+0

왜 FragmentTransaction.replace를 사용 하시겠습니까? 어쩌면 스타트 업을 시작해야할까요? – pskink

+0

u님께 서 android.R.id.content를 시도하셨습니까? –

+0

나는 당신이 아이템을 클릭 할 때 콜백 함수를 사용하여 하나의 인터페이스를 구현했다고 생각해 거기에 새로운 조각 코드를 대체하려고한다. –

답변

0

먼저 레이아웃을 정의합니다. 예를 들어,

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <!-- The main content view --> 

    <FrameLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
    <!-- The navigation drawer --> 

    <ListView 
     android:id="@+id/left_drawer" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@color/WhiteSmoke" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" /> 

</android.support.v4.widget.DrawerLayout> 

위와 같이 'content_frame'인 Framelayout에서 조각을 변경한다고 가정합니다. newFragment 당신이 이동하고자하는 조각 인 경우

그런 다음 해당 코드는

 FragmentManager fragmentManager = getFragmentManager(); 
     FragmentTransaction fragmentTransaction =fragmentManager.beginTransaction(); 
     fragmentTransaction.replace(R.id.content_frame,new newFragment()); 
     fragmentTransaction.commit(); 

될 것입니다.

0

하는 우리는 추가해야하는 레이아웃-ID를 포함 할 수있다 조각을 들고 당신의 활동 우리 조각.

예를 들어 내 활동 잡고 fragmets는 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragmentgroup" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal" > </LinearLayout>

당신이이 경우에 R.id.fragmentgroup을 지정해야합니다. ID는 우리가 조각을 배치해야하는 레이아웃입니다.

관련 문제