问题
I m creating a class that extends AlertDialog. and setting layout. But when pop up is called,
**1) layout is transparent
2) buttons not visible even after calling setButton ** I don't know what to do with , and no Idea why its happening.
My classes are this DateTimeDialog.java
public class DateTimeDialog extends AlertDialog{
Date date;
String title;
DialogInterface.OnClickListener listner;
protected DateTimeDialog(Context context, String title, Date date ) {
super(context);
// TODO Auto-generated constructor stub
this.title = title;
this.date = date;
}
public void initListener(DialogInterface.OnClickListener listner){
this.listner = listner;
}
public Date getDate(){
return date;
}
@Override
public void onCreate(Bundle savedInstanceState){
//super.onCreate(savedInstanceState);
setContentView(R.layout.date_time_picker);
setTitle(title);
setButton( "OK", listner);
setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do something
dialog.dismiss();
}
});
}
method that is calling this class
final DateTimeDialog dateTimeDialog = new DateTimeDialog(context, "title", time);
dateTimeDialog.show();
dateTimeDialog.initListener(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
//doSomething
}
});
Please help.....
回答1:
When you call setContentView, you override any and all content the AlertDialog class provides. If you want to set the content view yourself, you need to add the buttons in the XML file and set listeners.
来源:https://stackoverflow.com/questions/10991805/button-not-shown-in-alertdialog