我想把主活动接收到的数据实时地显示在alertdialog上,点击alertdialog中自定义的按钮能够调用主活动中的发送数据的方法,但是实际调试发现按钮不响应,数据也不显示
alertDialog=new AlertDialog.Builder(SecondActivity.this)
.setView(R.layout.dialog_window)
.create();
LayoutInflater inflater = LayoutInflater.from(SecondActivity.this);
View dialogView=inflater.inflate(R.layout.dialog_window, null);
Button sendMessage = (Button)dialogView.findViewById(R.id.sendMessage);
final EditText editText=(EditText) dialogView.findViewById(R.id.editText);
responseData=(TextView) dialogView.findViewById(R.id.response_data);
sendMessage.setOnClickListener(view -> {
if(alertDialog!=null && alertDialog.isShowing()) {
Log.e("alertdialog", "onCreate: ");
String message = editText.getText().toString();
if (message != null) {
byte[] byteMessage = message.getBytes();
writeBytes(byteMessage);
}
}
});
alertDialog.show();