-1
我想要得到一個片段以顯示在Android中。當我執行代碼去正確的片段時,我所看到的就是敬酒。 fragment_detail沒有出現。有沒有人知道這段代碼有什麼問題? 從調用類:Android片段不能正常工作
final FragmentManager fm = getActivity().getSupportFragmentManager();
final FragmentTransaction ft = fm.beginTransaction();
DetailFragment df = new DetailFragment();
ft.replace(R.id.pager, df, "DetailFragment").setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).commit();
從所謂類:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
Toast.makeText(getActivity().getBaseContext(), "Blah de Blah", Toast.LENGTH_LONG).show();
return rootView;
}
的佈局fragment_detail:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/fragment_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</FrameLayout>
</LinearLayout>
謝謝!
(R.id.pager,DDF,「 DetailFragment「)'ddf或df? – 2014-10-10 04:58:48
對不起,錯字已被更正。 – user2078519 2014-10-10 16:30:31