0

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

jack_the_beast
  • 1,838
  • 4
  • 34
  • 67
  • 1
    Why not using `DialogFragment` instead of `Dialog` ? – ρяσѕρєя K Oct 26 '15 at 16:30
  • As stated in the question, I tried but it doesn't compile, maybe I don't completely understand how a DialogFragment works – jack_the_beast Oct 26 '15 at 16:40
  • I think I figure out why I can't use a `DialogFragment`, it looks like the fragment class to be used in a `DialogFragment` must extends `DialogFragment`, I can't do that, I already have the fragment class (extending `Fragment`) and changing that is not possible – jack_the_beast Oct 27 '15 at 08:08

1 Answers1

0

I was able to solve the problem using a DialogFragment containing a FrameLayout and adding my fragment to this frame. I think it's not the best way to do this, but it's working at least

DialogFragment:

public FleetSelectDialog() {

}
public static FleetSelectDialog newInstance() {
    FleetSelectDialog dialogFragment = new FleetSelectDialog();
    return dialogFragment;
}

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState);

    fragmentFleetList = new FragmentFleetListReports();

    getChildFragmentManager().beginTransaction().add(R.id.list_select_frame, fragmentFleetList).commit();

}

calling it this way:

fleetSelectDialog = FleetSelectDialog.newInstance();
                fleetSelectDialog.show(getFragmentManager(), "");
jack_the_beast
  • 1,838
  • 4
  • 34
  • 67