I have a quite complex situation, I'll try to explain:
I have three classes:
FleetListFragment extends android.support.v4.app.Fragment
FragmentFleetListMap extends FleetListFragment
FragmentFleetListReports extends FleetListFragment
now, this app is made of a drawer activity, which of course uses fragments; FragmentFleetListMap
is used as a child fragment in one of the "main" fragments of the activity.
I want to use FragmentFleetListReports
inside a custom dialog (FleetSelectDialog
, which also contains other things) which is shown by one of the main fragments.
I tried this:
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();
}
with fragmentManager passed from the main fragment: new FleetSelectDialog(context, getFragmentManager());
this gives this error:
java.lang.IllegalArgumentException: No view found for id 0x7f0e0086 (com.Tierra:id/list_select_frame) for fragment FragmentFleetListReports
The other thing I tried is changing the dialog to be a DialogFragment
but:
getChildFragmentManager().beginTransaction().add(R.id.list_select_frame, new FragmentFleetListReports(this)).commit();
does not compile giving the error: cannot resolve method: add(int, myPackage.FragmentFleetListReports)
just like if FragmentFleetListReports
is not extending Fragment
dialog layout looks like this:
<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>
I think I am missing something (especially on how DialogFragment
works...) but I can't figure out how to solve this. Moving the other views to the fragment is not an option and neither is not using the fragment
if anyone can give any help, it would be great, thanks