Why Is My Custom Alert Dialog Code Crashing?
I'm trying to apply custom view to alert dialog. I'm doing like this, but there is nullpointer exception when I try to show the alert box. I create a layout.xml like so:
Solution 1:
public class BranchDialog extends android.app.Dialog
{
ListView list;
Context context;
TextView title;
ProgressBar progress;
public BranchDialog(Context context, String rid, String name)
{
super(context);
setContentView(R.layout.branch_dialog);
setCancelable(true);
setTitle(name);
this.context = context;
title = (TextView)findViewById(R.id.branch_dialog_title);
title.setText("this is my custom title");
show();
}
}
may be help full for you after a bit changing.
Solution 2:
Try with these code for Alert Dialog its working for me
AlertDialog.Builder alert;
alert = new AlertDialog.Builder(Deal_Purchase_Checkout.this);
alert.setTitle("Enter Your Title");
alert.setView(input);
alert.setPositiveButton("Ok",new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int whichButton){
//Some Code
}
});
alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton) {
dialog.cancel();
}
});
alert.show();
Post a Comment for "Why Is My Custom Alert Dialog Code Crashing?"