I have following standard custom view. Can't initialize R.id.text value before dialog is shown.
boolean wrapInScrollView = true;
new MaterialDialog.Builder(this)
.title(R.string.title)
.customView(R.layout.custom_view_edittext, wrapInScrollView)
.positiveText(R.string.positive)
.build()
.show();
custom_view_edittext.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text=""/>
</LinearLayout>
Just updated your description to apply syntax highlighting and formatting to your code.
You can use something similar to this:
MaterialDialog dialog = new MaterialDialog.Builder(this)
.title(R.string.title)
.customView(R.layout.custom_view_edittext, true)
.positiveText(R.string.positive)
.build();
EditText text = (EditText) dialog.getCustomView();
text.setText("Hi!");
dialog.show();
Also, if you don't need an instance of a MaterialDialog like you do here, you can skip using build() and just go right to show().
Great! big thanks!
why this force close?
MaterialDialog mDialog = new MaterialDialog.Builder(getActivity())
.title("Cancel order")
.customView(R.layout.dialog_cancel_order, true)
.positiveText("SUBMIT")
.negativeText("CANCEL")
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which)
{
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
})
.build();
EditText etId = (EditText)mDialog.getCustomView();
etId.setText("How");
mDialog.show();
Most helpful comment
Just updated your description to apply syntax highlighting and formatting to your code.
You can use something similar to this: