Dialog opens blank

前端 未结 1 1521
刺人心
刺人心 2021-01-23 15:02

i recently switched to AndEngine to play a little bit around with this engine. Before the switch i already implemented a DialogFragment wich worked just fine. Now i

1条回答
  •  心在旅途
    2021-01-23 15:36

    The problem is that you are using the AlertDialog.Builder rather than modifying your own instance of the Dialog. AlertDialog.Builder creates its own AlertDialog, and modifies that instance instead. It does not, and will not affect your SimpleDialog instance.

    Since you are already using the Builder to create your Dialog I don't see a need for extending Dialog itself. Why not move the Builder code into a method or a wrapper class, and call the method directly?

    Something like this:

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

    To run:

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

    0 讨论(0)
提交回复
热议问题