Directly paste the Code:
Jsdmaindialog. Java
Package com. JSD. Demo;
Import Android. App. activity;
Import Android. content. context;
Import Android. Graphics. color;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. OS. message;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;
Import Android. widget. textview;
/**
*
* @ Author jiangshide
*
*/
Public class jsdmaindialog extends activity {
Private context mcontext;
Private button Msub;
Private textview mresultvalue;
Public static handler = new handler ();
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Getviewbyid ();
}
Public void getviewbyid (){
Mcontext = this;
Msub = (button) This. findviewbyid (R. Id. sub );
Mresultvalue = (textview) This. findviewbyid (R. Id. resultvalue );
Mresultvalue. settext ("handler not processed ");
Msub. setonclicklistener (listener );
}
Private onclicklistener listener = new onclicklistener (){
@ Override
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. Sub:
Final string flag = "rqbackvalue ";
Dialogcustomer Dc = new dialogcustomer (mcontext, flag );
DC. Show ();
Handler = new handler (){
Public void handlemessage (Message MSG ){
String resultflag = msg. getdata (). getstring ("Flags ");
If (resultflag. equalsignorecase (FLAG )){
Mresultvalue. settext ("this is the data that is later displayed after handler processing ");
Mresultvalue. settextcolor (color. Cyan );
Mresultvalue. settextsize (30 );
}
};
};
Break;
Default:
Break;
}
}
};
}
Dialogcustomer. Java:
Package com. JSD. Demo;
Import Android. App. Dialog;
Import Android. content. context;
Import Android. OS. Bundle;
Import Android. OS. message;
Import Android. View. view;
Import Android. widget. Button;
/**
*
* @ Author jiangshide
*
*/
Public class dialogcustomer extends dialog {
Private context mcontext;
Private button OK;
String flag;
Public dialogcustomer (context c, string flag ){
Super (C );
This. mcontext = C;
This. Flag = flag;
}
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Dialog );
Getviewbyid ();
}
Public void getviewbyid (){
OK = (button) This. findviewbyid (R. Id. dialog_ OK );
OK. setonclicklistener (listener );
}
Private Android. View. View. onclicklistener listener = new Android. View. View. onclicklistener (){
@ Override
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. dialog_ OK:
Message MSG = new message (); // get and set an information save point
MSG. What = 1;
MSG. getdata (). putstring ("Flags", flag );
Jsdmaindialog. handler. sendmessage (MSG); // put the data in the logoff queue
Dismiss ();
Break;
}
}
};
}
Dialog. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: Orientation = "vertical"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "when a response is returned, the parameter is passed and the operation after judgment is executed"
/>
<Button
Android: Id = "@ + ID/dialog_ OK"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "click"
/>
</Linearlayout>
Address: http://blog.csdn.net/jiangshide/article/details/6434597