Dialog Fragment正在崩溃

时间:2014-11-20 17:08:03

标签: java android

我有一个显示使用的Dialog片段。顺便说一下,我更新了我的支持库,包括材料设计主题和新类。是否有可能新的fragmentDialog片段是错误的

fragment.show(getSupportedFragmentManager(),null);

这是片段的代码

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();
    }
}

这里的错误是获取

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)

最后这里是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>

0 个答案:

没有答案