Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对话框打开为空白_Android_Android Alertdialog - Fatal编程技术网

Android 对话框打开为空白

Android 对话框打开为空白,android,android-alertdialog,Android,Android Alertdialog,我最近转用了安德林发动机,用这台发动机玩了一会儿。在切换之前,我已经实现了一个工作正常的对话框片段。现在我想把这个对话框片段移植到安德林。因为AndEngine中不支持FragmentActivity(据我所知),所以我决定将代码改为一个简单的对话框。 现在对话框打开得很好,但完全为空。只有一个带边框的黑色小矩形 我看不出我的代码有什么问题……也许你能帮我 public class SimpleDialog extends Dialog { final long number;

我最近转用了安德林发动机,用这台发动机玩了一会儿。在切换之前,我已经实现了一个工作正常的
对话框片段。现在我想把这个
对话框片段
移植到安德林。因为AndEngine中不支持FragmentActivity(据我所知),所以我决定将代码改为一个简单的
对话框。
现在对话框打开得很好,但完全为空。只有一个带边框的黑色小矩形

我看不出我的代码有什么问题……也许你能帮我

public class SimpleDialog extends Dialog {

    final long number;
    Context context;

    public SimpleDialog (Context context, long number) {
        super(context);
        this.number = number;
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        LayoutInflater inflater = ResourceManager.getInstance().activity.getLayoutInflater();

        final View view = inflater.inflate(R.layout.logindialog, null);

        final EditText editTextUserName = (EditText) view.findViewById(R.id.usernameToSubmit);
        final EditText editTextPassword = (EditText) view.findViewById(R.id.passwordToSubmit);

        TextView numberText = (TextView) view.findViewById(R.id.numberText);
        highscoreText.setText("Number: " + Long.toString(number));

        builder.setView(view)
        .setNegativeButton(R.string.login_submit, null)
        .setPositiveButton(R.string.login_abort, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dismiss();
            }
        });

        final AlertDialog d = builder.create();

        d.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                Button b = d.getButton(AlertDialog.BUTTON_NEGATIVE);

                b.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                    }
                });

            }
        });
    }
以下是我打开对话框的方式:

ResourceManager.getInstance().activity.runOnUiThread(new Runnable() {

    @Override
    public void run() {
        new SimpleDialog(ResourceManager.getInstance().activity, number).show();
    }

});
如果你也需要我的布局,请让我知道。
非常感谢

问题在于您使用的是
AlertDialog.Builder
,而不是修改自己的对话框实例<代码>AlertDialog.Builder
创建自己的AlertDialog,并修改该实例。它不会也不会影响您的
SimpleDialog
实例

由于您已经在使用构建器创建对话框,因此我认为没有必要扩展
对话框本身。为什么不将构建器代码移动到方法或包装类中,并直接调用该方法

大概是这样的:

public class DialogRunner {

  public static void createAndShowDialog (Context context, long number){
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LayoutInflater inflater = LayoutInflater.from (context);

    final View view = inflater.inflate(R.layout.logindialog, null);

    final EditText editTextUserName = (EditText) view.findViewById(R.id.usernameToSubmit);
    final EditText editTextPassword = (EditText) view.findViewById(R.id.passwordToSubmit);

    TextView numberText = (TextView) view.findViewById(R.id.numberText);
    highscoreText.setText("Number: " + Long.toString(number));

    builder.setView(view)
      .setNegativeButton(R.string.login_submit, null)
      .setPositiveButton(R.string.login_abort, new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface dialog, int which) {
        dismiss();
      }
    });

    final AlertDialog d = builder.create();

    d.setOnShowListener(new DialogInterface.OnShowListener() {

      @Override
      public void onShow(DialogInterface dialog) {
        Button b = d.getButton(AlertDialog.BUTTON_NEGATIVE);

        b.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {

          }
        });

      }
    });

    d.show();
  }
}
要运行:

ResourceManager.getInstance().activity.runOnUiThread(new Runnable() {

    @Override
    public void run() {
        DialogRunner.createAndShowDialog(ResourceManager.getInstance().activity, number);
    }

});

问题是您使用的是
AlertDialog.Builder
,而不是修改自己的对话框实例<代码>AlertDialog.Builder
创建自己的AlertDialog,并修改该实例。它不会也不会影响您的
SimpleDialog
实例

由于您已经在使用构建器创建对话框,因此我认为没有必要扩展
对话框本身。为什么不将构建器代码移动到方法或包装类中,并直接调用该方法

大概是这样的:

public class DialogRunner {

  public static void createAndShowDialog (Context context, long number){
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LayoutInflater inflater = LayoutInflater.from (context);

    final View view = inflater.inflate(R.layout.logindialog, null);

    final EditText editTextUserName = (EditText) view.findViewById(R.id.usernameToSubmit);
    final EditText editTextPassword = (EditText) view.findViewById(R.id.passwordToSubmit);

    TextView numberText = (TextView) view.findViewById(R.id.numberText);
    highscoreText.setText("Number: " + Long.toString(number));

    builder.setView(view)
      .setNegativeButton(R.string.login_submit, null)
      .setPositiveButton(R.string.login_abort, new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface dialog, int which) {
        dismiss();
      }
    });

    final AlertDialog d = builder.create();

    d.setOnShowListener(new DialogInterface.OnShowListener() {

      @Override
      public void onShow(DialogInterface dialog) {
        Button b = d.getButton(AlertDialog.BUTTON_NEGATIVE);

        b.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {

          }
        });

      }
    });

    d.show();
  }
}
要运行:

ResourceManager.getInstance().activity.runOnUiThread(new Runnable() {

    @Override
    public void run() {
        DialogRunner.createAndShowDialog(ResourceManager.getInstance().activity, number);
    }

});

谢谢你的解释。它就像一个符咒:)@puelo没问题:-).setNegativeButton(R.string.login_submit,null)。setPositiveButton(R.string.login_abort,new DialogInterface.OnClickListener(){应该是.setNegativeButton(R.string.login_abort,null)。setPositiveButton(R.string.login_submit,new DialogInterface.OnClickListener()){谢谢你的解释。它就像一个符咒:)@puelo没问题:-).setNegativeButton(R.string.login_submit,null)。setPositiveButton(R.string.login_abort,new DialogInterface.OnClickListener(){应该是.setNegativeButton(R.string.login_abort,null)。setPositiveButton(R.string.login\u submit,new DialogInterface.OnClickListener(){