Android - Custom Dialog - Can't get text from EditText

前端 未结 6 781
清歌不尽
清歌不尽 2020-12-01 12:00

I have a problem with a custom dialog.
My dialog consists of a TextView, EditText and an \"Ok\" Button. After clicking \"Ok\", it should get t

6条回答
  •  青春惊慌失措
    2020-12-01 12:43

    An alternative to matsjoe and to krishna (both work):

    builder.setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() {
        //@Override
        public void onClick(DialogInterface dialog, int id) {
          // sign in the user ...
    
          Dialog dialogObj =Dialog.class.cast(dialog);
          EditText etUsr=(EditText) dialogObj.findViewById(R.id.username_id_value);
          userStr = etUsr.getText().toString();      
        }
      }
      );
    

    Kf

提交回复
热议问题