我試圖從對話框中獲取文本,但它不起作用。所有的代碼作品除了username = txtDialog.getText().toString();
Android對話框EditText不賦值
我得到一個NullPointerException
下面是完整的代碼:
btn_next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog = new Dialog(ResActivity.this);
dialog.setContentView(R.layout.custom);
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
txtDialog = (EditText)findViewById(R.id.textDialog);
username = txtDialog.getText().toString();
Intent intent = new Intent(getApplicationContext(), EndActivity.class);
intent.putExtra(MESSAGE_NAME, username);
startActivity(intent);
dialog.dismiss();
}
});
}
});
有人能幫忙嗎?
發佈錯誤日誌。 –
edittext在對話框中? –