6
我有,我需要顯示在android.app.Dialog
內部對話
這裏fragment
一個問題,Android的碎片是XML代碼
<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/marchecharts"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
我想是我的片段取代marchecharts
,任何人都可以幫助
感謝
Dialog dialog = new Dialog(getActivity());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.marche_charts_parent);
//this is the part I think I need
Fragment fragment = new MarcheChartsFragment();
FragmentTransaction ft = ((FragmentActivity) dialog.getOwnerActivity()).getFragmentManager().beginTransaction();
ft.replace(R.id.marchecharts, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
dialog.setCanceledOnTouchOutside(true);
dialog.getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
dialog.show();
感謝您的迴應! 我在onCreateDialog中出現錯誤:類型不匹配:無法從視圖轉換爲對話框在「返回視圖」行 –
第二想法,我不認爲這回答了問題,因爲我已經有一個片段在手中,我只需要顯示它在對話框 –
據我瞭解你的問題。你想在對話框中顯示你自己的片段。如果這是你的問題,我提供的代碼說明了這一點。 – HpTerm