조각과 백 스택이 작동하는 데 문제가 있습니다.조각이 백 스택에 추가되지 않았습니다.
나는 다양한 조각과 다른 조각을 보유하기위한 FrameLayout이있는 레이아웃을 가지고 :
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/filterableListContainer"
android:layout_weight="50">
</FrameLayout>
<fragment class="com.facetoe.remotempd.fragments.PlayerBarFragment"
android:id="@+id/playerBarFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
tools:layout="@layout/player_bar"/>
</LinearLayout>
나는 그렇게처럼 FrameLayout이에 조각을 추가 할 레이아웃 사용하는 작업 시작할 때 :
을 사용자가 항목을 클릭하면@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
if (findViewById(R.id.filterableListContainer) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
// Create a new Fragment to be placed in the activity layout
ArtistListFragment listFragment = new ArtistListFragment();
// Add the fragment to the 'fragment_container' FrameLayout
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.filterableListContainer, listFragment);
ft.addToBackStack(null);
ft.commit();
} else {
Log.e(TAG, "Couldn't find filterableListFragment");
}
}
, 나는이 코드 조각을 교체하려고 :
ArtistAlbumsListFragment fragment = new ArtistAlbumsListFragment(getActivity(), albums);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.filterableListContainer, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
그러나 뒤로 버튼을 누르면 홈 화면으로 돌아갑니다. 아무도 내가 잘못 가고 있다고 말할 수 있습니까?
조각을 백 스택에 추가해야합니다. – Raghunandan
ft.addToBackStack (null); 백 스택에 조각을 추가 하시겠습니까? – facetoe
그것은 작동합니다. – Raghunandan