我已经创建了一个自定义AlertDialog,并且正在尝试为EditTexts设置文本。我试过以下在AlertDialog中设置EditText
public class CheckListDialog extends DialogFragment {
private View view;
public CheckListDialog(View view) {
this.view = view;
}
@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogLayout = inflater.inflate(R.layout.dialog_checklist, null);
EditText etCost = (EditText) dialogLayout.findViewById(R.id.etCost);
EditText etOdoReading = (EditText) dialogLayout.findViewById(R.id.etOdometer);
etOdoReading.setText("bla");
etCost.setText("tada");
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(Reminders.this, android.R.color.transparent));
builder.setView(inflater.inflate(R.layout.dialog_checklist, null))
.setTitle("jaja")
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
return builder.create();
}
}
EditTexts是空的并且不包含值。我怎样才能解决这个问题?
你再次膨胀布局 – Raghunandan