简体   繁体   English

对话框未从Android中的fragmentActivity显示

[英]Dialog not displaying from fragmentActivity in android

I want to display a dialog inside the class that extends FragmentActivity.I have tried in many ways.Atlast I tried this link . 我想在扩展FragmentActivity的类内显示一个对话框。我尝试了很多方法。最后,我尝试了此链接 I have tried the samething but iam getting the following error message. 我已经尝试过相同的方法,但是我收到以下错误消息。

  05-14 10:15:28.821: E/AndroidRuntime(2927): java.lang.IllegalStateException: Activity has been destroyed
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at   android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1342)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:595)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:574)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.support.v4.app.DialogFragment.show(DialogFragment.java:127)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.sriseshaa.ecgviewer.FragmentTabActivity$1$1.run(FragmentTabActivity.java:70)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Handler.handleCallback(Handler.java:725)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Handler.dispatchMessage(Handler.java:92)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.os.Looper.loop(Looper.java:137)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at android.app.ActivityThread.main(ActivityThread.java:5039)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at java.lang.reflect.Method.invokeNative(Native Method)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at java.lang.reflect.Method.invoke(Method.java:511)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-14 10:15:28.821: E/AndroidRuntime(2927):   at dalvik.system.NativeStart.main(Native Method)

FragmentTabActivity.java:70 is FragmentTabActivity.java:70是

   adFragment.show(getSupportFragmentManager(), "dialog");

I have called the dialog by the following code snippet 我通过以下代码片段调用了对话框

          Bundle bundle = new Bundle();  
          bundle.putString("title", "Message");  
          bundle.putString("message", StaticHelper.l);  
          bundle.putString("positive", "Ok");  
          bundle.putString("negative", "Cancel");  
          // bundle.putInt("id", mIndex++);  
          AlertDialogFragment adFragment = new AlertDialogFragment();  
          adFragment.setArguments(bundle);  
          adFragment.show(getSupportFragmentManager(), "dialog");  

What I have missed? 我错过了什么? and what is the problem in this? 这是什么问题呢? please help me.Thank u!! 请帮助我。谢谢!

If you really want to display an alertdialog what is your problem of using AlertDialog.Builder as following. 如果您确实要显示AlertDialog,则使用AlertDialog.Builder的问题如下。

    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setIcon(R.drawable.ic_launcher);
    dialog.setTitle("Title");
    dialog.setMessage("Message");
    dialog.setPositiveButton("yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

        }
       });
       dialog.setNegativeButton("no", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
      });
      dialog.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM