我正在使用afollestad MaterialDialog Library
(https://github.com/afollestad/material-dialogs)
并使用自定义视图。内部视图中有五个输入和微调框。但是我试图从输入中获取价值,但是没有用。另外,我需要从api填充微调框。
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title("Edit Paid Amount")
.customView(R.layout.edit_payment_model, true)
.positiveText("Update Payment").build();
Spinner spinner= (Spinner) dialog.getCustomView();
dialog.show();
任何人都可以帮助我实现这一目标吗?
我尝试了默认警报对话框的工作方式
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView= inflater.inflate(R.layout.edit_payment_model, null);
dialogBuilder.setView(dialogView);
EditText editText = (EditText)
dialogView.findViewById(R.id.editPaymentAmount);
editText.setText("test label");
dialogBuilder.create().show();
即使我检查了此问题,https://github.com/afollestad/material-dialogs/issues/230
答案 0 :(得分:1)
我对该库不熟悉,但是您应该在自定义视图中找到Spinner / edittext视图。
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title("Edit Paid Amount")
.customView(R.layout.edit_payment_model, true)
.positiveText("Update Payment")
.build();
View customView = dialog.getCustomView();
Spinner spinner = (Spinner) customView.findViewById(R.id.spinner)
EditText editText = (EditText) customView.findViewById(R.id.editPaymentAmount);
editText.setText("test label");
dialog.show();
答案 1 :(得分:0)
如果我理解,从AlertDialog内部的View获取值的方法
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.edit_license, null);
builder.setView(dialogView)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText valueView = (EditText) dialogView.findViewById(R.id.license_value); //here
if(valueView == null) Log.d("AA", "NULL");
else{
String value = valueView.getText().toString();
mListener.onDialogPositiveClick(EditLicenseDialogFragment.this, value);
}
})
您进行的很好,但是要获取值,必须直接从被调用的View中获取它。