I'm doing customized AlertDialog as indicated below:
public class Message {
private static AlertDialog.Builder alertDialog;
private final static Handler m_handler = new Handler() {
@Override
public void handleMessage(Message mesg) {
throw new RuntimeException();
}
};
public static void simpleMessage(String Message, String textButton, Context act){
alertDialog = new AlertDialog.Builder(act);
LayoutInflater inflater = (LayoutInflater) act.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View v = inflater.inflate(R.layout.message_simple,null);
TextView tvMessageSimple = (TextView) v.findViewById(R.id.tv_message_simple);
Button btnOKMessageSimple = (Button) v.findViewById(R.id.btn_ok_message_simple);
tvMessageSimple.setText(message);
btnOKMessageSimple.setText(textButton);
alertDialog.setView(v);
alertDialog.show();
btnOKMessageSimple.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m_handler.sendMessage(m_handler.obtainMessage());
}
});
// loop till a runtime exception is triggered.
try {
Looper.loop();
}
catch(RuntimeException e2) {
;
}
}
}
The AlertDialog works very well and when the button is pressed, it should finish the AlertDialog.
When the button is pressed, the catch (RuntimeException e2) is executed, but the AlertDialog ends.
How should I finish it?
Thanks.