我有一個相當複雜的情況下不能使用的片段,我會盡力解釋:Android的:在一個對話框
我有三類:
FleetListFragment extends android.support.v4.app.Fragment
FragmentFleetListMap extends FleetListFragment
FragmentFleetListReports extends FleetListFragment
現在,這個程序是由抽屜活動,當然使用碎片; FragmentFleetListMap
用作活動「主要」片段之一的子片段。
我想在自定義對話框中使用FragmentFleetListReports
(FleetSelectDialog
,其中還包含其他內容),它由一個主要片段顯示。
我嘗試這樣做:new FleetSelectDialog(context, getFragmentManager());
這給出了這樣的錯誤:
java.lang.IllegalArgumentException: No view found for id 0x7f0e0086 (com.Tierra:id/list_select_frame) for fragment FragmentFleetListReports
我想其他的事情正在改變對話框
public class FleetSelectDialog extends Dialog{
public FleetSelectDialog(Context context, FragmentManager fragmentManager) {
super(context);
this.context = context;
this.fragmentManager = fragmentManager;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View v = inflater.inflate(R.layout.fleet_select_dialog, null);
fragmentManager.beginTransaction().add(R.id.list_select_frame, new FragmentFleetListReports(this)).commit();
}
與fragmentManager從主片段通過是DialogFragment
但是:
getChildFragmentManager().beginTransaction().add(R.id.list_select_frame, new FragmentFleetListReports(this)).commit();
不編譯給人錯誤:cannot resolve method: add(int, myPackage.FragmentFleetListReports)
就像如果FragmentFleetListReports
不延長片段
對話框佈局如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fleet_select_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<FrameLayout
android:id="@+id/list_select_frame"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/footerview"/>
<RelativeLayout
android:id="@+id/footerview"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_alignParentBottom="true">
<!--other views-->
</RelativeLayout>
</RelativeLayout>
我想我失去了一些東西(特別是對如何DialogFragment
作品...)但我無法弄清楚如何解決這個問題。移動其他視圖片段是不是一種選擇,既沒有使用片段
如果任何人都可以提供任何幫助,這將是巨大的,感謝
:
}
叫它這樣? –
正如問題所述,我試過但它不編譯,也許我不完全瞭解DialogFragment如何工作 –
我想我找出爲什麼我不能使用'DialogFragment',它看起來像片段類要在DialogFragment中使用,必須擴展DialogFragment,我不能這樣做,我已經有了片段類(擴展了'Fragment')並且改變了這一點,這是不可能的 –