I defined a CustomDialog class as follow :
public class CustomDialog {
Dialog dialog;
public void show(Contex contex, int duration){
Handler timeHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
dialog.dismiss();
break;
default:
break;
}
};
dialog = new dialog(contex);
dialog.show();
Message message = new Message();
message.what = 1 ;
timeHandler.sendMessageDelayed(message, duration);
}
}
In the Activity , I new an CustomDialog object , and call the show() method , but the dialog can not close automatically , could anybody tell me why ?
The code in the activity :
CustomDialog myDialog = new CustomDialog();
myDialog.show(this,2000);
It did not work.Is it a formal way to create a custom dialog ? If it’s not , could anyone tell me what is the right way to create one ?
1 Answer