Alert.Dialog 生成器代码无法访问

Alert.Dialog builder code unreachable

我试图在 android 工作室中制作对话框警报。但这里显示代码无法访问。请帮帮我。

public class Mydialog extends DialogFragment
{

@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    AlertDialog.Builder theDialog = new AlertDialog.Builder(getActivity());
    theDialog.setTitle("Sample Dialog");
    theDialog.setMessage("hello world");
    return super.onCreateDialog(savedInstanceState);
    theDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            toasty("Clicked Ok");
        }
    });



}

public void toasty(String str)
{

    Toast.makeText(getActivity(),str,Toast.LENGTH_SHORT).show();
}
}

嗯,那是因为你 return super.onCreateDialog(savedInstanceState); 在方法结束之前。将此行放在 onCreateDialog().

的末尾

编辑

抱歉,我的意思是删除此行并添加到末尾:

return theDialog.create();