我有一个自定义对话框,当我尝试获取EditText的值时,它返回null。findviewbyid在对话框中返回空值
此行返回null
EditText et = (EditText)findViewById(R.id.username_edit);
这里是将其全部的代码。
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_TEXT_ENTRY:
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
return new AlertDialog.Builder(TicTacToe.this)
//.setIconAttribute(android.R.attr.alertDialogIcon)
.setTitle(getTitleText())
.setView(textEntryView)
.setPositiveButton("JOIN GAME", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try
{
EditText et = (EditText)findViewById(R.id.username_edit);
playerName = et.getText().toString();
}
catch (Exception e)
{
}
}
})
.create();
}
return null;
}
+1伟大的工作人。 – Jacob 2013-03-07 13:01:14
谢谢!为我工作以及 – Urbanleg 2013-06-15 15:10:52
谢谢你保存了一天:) – orchidrudra 2015-04-23 20:38:23