且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

EditText getText()返回空字符串

更新时间:2023-02-18 20:47:24

初始化后,您getText.除非您在xml中有文本,否则您将无法获取文本.在alertdialog按钮的onclick中,获取文本.

You getText just after initialization. Untill you have text in xml you won't get the text. In onclick of alertdialog button get the text.

声明

EdiText ed1,ed2; // before onCreate if in activity and onCraeteView in fragment

作为实例变量

View view = getLayoutInflater().inflate(R.layout.login_alert, null, false);
ed1= (EditText) view.findViewById(R.id.emailEditText))
ed2 = (EditText) view.findViewById(R.id.emailEditText);

然后在警告"对话框中单击按钮

then on Alert dialog Button click

  String email = ed1.getText().toString();
  String password= ed2.getText().toString()