I'm trying to create an alert dialog with an image header across the top, 2 buttons at the bottom and I want to set the text in the middle from code. However, I can't get the set text underneath the banner. I want to create something similar to the one on this link. However, the text always ends up above the image as I don't know how to reference the textview in the dialog builder. Thanks
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
builder.setView(inflater.inflate(R.layout.custom_dialog, null))
.setMessage("Message" + message)
.setPositiveButton("Share", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (isNetworkAvailable()) {
if (...) {...}
else {...}
} else {...}
}
})
.setNegativeButton("Shake again!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
})
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {}
});
AlertDialog alert = builder.create();
alert.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {}
});
alert.show();
The layout xml file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/yo3"
android:layout_width="match_parent"
android:layout_height="64dp"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name" />
<TextView
android:id="@+id/dialogtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>`