кода для создания строителя:как отправить данные от активности к AlertDialog, чтобы отобразить их
builder = new AlertDialog.Builder(this);
builder.setPositiveButton("connect",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
devices.get(currentPos).setConnected(true);
}
});
builder.setNegativeButton("dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
builder.setView(getLayoutInflater().inflate(
(R.layout.activity_device_details), null));
builder.setTitle("more information");
Обратите внимание на: builder.setView() для R.layout.activity_device_details, которые имеют некоторые TextViews, что я хочу, чтобы заполнить когда Я создаю диалог с этим кодом:
BPDevice dev = new BPDevice();
dev = devices.get(position);
AlertDialog dialog = builder.create();
((TextView) dialog.findViewById(R.id.name)).setText(dev.getName());
dialog.show();
Я получаю NullPointerException из-за этой линии:. ((TextView) dialog.findViewById (R.id.name)) SetText (dev.getName());
¿Как я могу правильно заполнить TextViews?
Проверить dev.getName() null или нет. –
Я проверил. Это не null :( – martencarlos