2014-05-11 10 views

답변

0

이 예는 단순히 이미지를 전환하는 것이 아닙니다. 더 자세히 보면 더 이상 선택되지 않은 항목에 대해 새 Fragment이 생성되는 것을 볼 수 있습니다. 그것은 "클래스 간 전환"이라고 할 때 가장 많이 사용하는 구성 요소입니다.

private void selectItem(int position) { 
    // Create a new fragment and specify the planet to show based on position 
    Fragment fragment = new PlanetFragment(); 
    Bundle args = new Bundle(); 
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); 
    fragment.setArguments(args); 

    // Insert the fragment by replacing any existing fragment 
    FragmentManager fragmentManager = getFragmentManager(); 
    fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, fragment) 
        .commit(); 

    // Highlight the selected item, update the title, and close the drawer 
    mDrawerList.setItemChecked(position, true); 
    setTitle(mPlanetTitles[position]); 
    mDrawerLayout.closeDrawer(mDrawerList); 
}