0

i have a Dialog fragment that i show using. Btw i have updated my support libraries to include material design theme and new classes. Is it possible that the new fragmentDialog fragments are buggy

fragment.show(getSupportedFragmentManager(),null);

here is the code for the fragment

public class NewTimedEvent extends DialogFragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_new_timed_event, container, false);
    }
    @Override // show User interface in a dialog
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.fragment_new_timed_event, null);
        builder.setView(view);
        builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });
        builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });
        // Create the AlertDialog object and return it
        return builder.create();
    }
}

here is the error is get

11-20 19:05:17.665  14612-14612/prototyping.materialdesign E/AndroidRuntime﹕ FATAL EXCEPTION: main
    android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:267)
            at com.android.internal.app.AlertController.installContent(AlertController.java:235)
            at android.app.AlertDialog.onCreate(AlertDialog.java:336)
            at android.app.Dialog.dispatchOnCreate(Dialog.java:351)
            at android.app.Dialog.show(Dialog.java:256)
            at android.support.v4.app.DialogFragment.onStart(DialogFragment.java:398)
            at android.support.v4.app.Fragment.performStart(Fragment.java:1810)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:977)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
            at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:454)
            at android.os.Handler.handleCallback(Handler.java:615)
            at android.os.Handler.dispatchMessage(Handler.java:92)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4898)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
            at dalvik.system.NativeStart.main(Native Method)

finally here is the code for Fragment UI

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="prototyping.materialdesign.NewTimedEvent">

    <LinearLayout
        android:paddingTop="10dp"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:showDividers="middle"
        android:divider="?android:dividerVertical">
        <TextView
            android:id="@+id/action_time"
            android:text="Action time"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            />
        <TextView
            android:id="@+id/time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="00:00"
            android:paddingRight="@dimen/activity_horizontal_margin"
            />
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#d0d0d0"/>
    <TextView
        android:id="@+id/days"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:textStyle="bold"
        android:text="Select Days for action to take place"
        android:layout_width="match_parent"

        android:layout_height="wrap_content" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <RadioButton
            android:id="@+id/sound"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/sound" />

        <RadioButton
            android:id="@+id/vibrate"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/vibrate" />

        <RadioButton
            android:id="@+id/silent"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/silent" />
    </RadioGroup>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <CheckBox
            android:id="@+id/wifi"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/wifi" />

        <CheckBox
            android:id="@+id/bluetooth"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/bluetooth" />

    </LinearLayout>
    <CheckBox
        android:id="@+id/airplane"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/airplane_mode"/>
    <EditText
        android:id="@+id/event_name"
        android:hint="Event name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>
user3553551
  • 75
  • 1
  • 7
  • 2
    Did you try adding a call to `requestFeature()` before adding content? – Patrick J Abare II Nov 20 '14 at 17:09
  • i tried but the compiler shows there is no such method – user3553551 Nov 20 '14 at 17:27
  • You must choose to override only one of onCreateView or onCreateDialog in a DialogFragment. Overriding both will result in the exception: "requestFeature() must be called before adding content". – Mohammed Ali Nov 20 '14 at 17:30
  • You can override both (in fact the DialogFragment says so), the problem comes when you try to inflate the view after having already creating the dialog view. You can still do other things in onCreateView, like use the savedInstanceState, without causing the exception. – Mohammed Ali Nov 20 '14 at 17:31
  • See Ans here including the comments : http://stackoverflow.com/a/15602648/3879470 – Mohammed Ali Nov 20 '14 at 17:31
  • @MohammedAli you were right. what do i return to the oncreateview if am not inflating the view – user3553551 Nov 20 '14 at 17:39
  • see this: http://stackoverflow.com/a/21643675/3879470 answers voted 9 and also 6... – Mohammed Ali Nov 20 '14 at 17:53

0 Answers0