Reputation: 11556
I am getting the following error while creating a custom Alert Dialog
in Android
application.
Error
requestFeature() must be called before adding content
Following is my code for the custom Alert Dialog
creation.
Code
AlertDialog alertDialog=new AlertDialog.Builder(home.this).create();
alertDialog.setTitle("Title here..");
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
Upvotes: 0
Views: 336
Reputation: 2969
Use this as guide:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
YourActivity.this);
alertDialogBuilder.setTitle("Your title here...");
alertDialogBuilder
.setMessage("Your message here...")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// Your works
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
Upvotes: 0
Reputation: 173
Try this :
AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(home.this);
alertDialogBuilder.setTitle("Title here..");
alertDialogBuilder.setContentView(R.layout.custom_alertdialog);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
Upvotes: 0
Reputation: 3140
Code snippet here for custom Dialog:
use new Dialog instead of DialogBuilder
Dialog d = new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("This is custom dialog box");
d.show();
Upvotes: 2