It's okay, just write a dialog box about the custom dialog box and use handler and timertask to regularly update the data of its custom dialog box. Because the custom dialog box is implemented separately to inherit the dailog, therefore, it may be a little difficult to update the data, so now I have made a small experiment and wrote the success as follows. The old rules are directly followed by code. What do programmers need:
The following is the main class:
Package org. Android. View. Dialog;
Import java. util. timer;
Import java. util. timertask;
Import org. Android. View. R;
Import Android. App. activity;
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;
/**
*
* @ Author jiangshide
*
*/
Public class mainactivity extends activity {
Private customerdialog dialog;
Public static handler = new handler ();
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. show_dialog );
Findviewbyid ();
}
Private void findviewbyid (){
Button showdailog = (button) findviewbyid (R. Id. showdailog );
Showdailog. setonclicklistener (listener );
}
Private onclicklistener listener = new onclicklistener (){
@ Override
Public void onclick (view v ){
Switch (V. GETID ()){
Case R. Id. showdailog:
Dialog = new customerdialog (mainactivity. This );
Dialog. Show ();
Timer time = new timer ();
Time. Schedule (New timertask (){
@ Override
Public void run (){
Message MSG = new message ();
MSG. What = 1;
MSG. getdata (). putstring ("name", "0002 ");
MSG. getdata (). putserializable ("daxiao", "10 m ");
MSG. getdata (). putstring ("chicun", "1299x1024 ");
MSG. getdata (). putstring ("time", "2011-09-02 ");
MSG. getdata (). putstring ("xiangce", "jsd002 ");
MSG. getdata (). putstring ("type", "jpg ");
Handler. sendmessage (MSG );
}
}, 5000,500 0 );
Break;
}
}
};
}
The following is a custom dialog:
Package org. Android. View. Dialog;
Import org. Android. View. R;
Import Android. App. Dialog;
Import Android. content. context;
Import Android. OS. Bundle;
Import Android. OS. Handler;
Import Android. OS. message;
Import Android. View. window;
Import Android. View. windowmanager;
Import Android. widget. textview;
/**
*
* @ Author jiangshide
*
*/
Public class customerdialog extends dialog {
Private context jcontext;
Private textview name;
Private textview daxiao;
Private textview chicun;
Private textview time;
Private textview xiangce;
Private textview type;
Public customerdialog (context c ){
Super (C );
This. jcontext = C;
}
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Requestwindowfeature (window. feature_no_title );
Getwindow (). setflags (windowmanager. layoutparams. flag_fullscreen,
Windowmanager. layoutparams. flag_fullscreen );
Setcontentview (R. layout. Dialog );
Findviewbyid ();
}
Private void findviewbyid (){
Name = (textview) findviewbyid (R. Id. Name );
Daxiao = (textview) findviewbyid (R. Id. daxiao );
Chicun = (textview) findviewbyid (R. Id. chicun );
Time = (textview) findviewbyid (R. Id. time );
Xiangce = (textview) findviewbyid (R. Id. xiangce );
Type = (textview) findviewbyid (R. Id. type );
Name. settext ("0001 ");
Daxiao. settext ("5 m ");
Chicun. settext ("1024x768 ");
Time. settext ("2011-05-20 ");
Xiangce. settext ("jsd01 ");
Type. settext ("GIF ");
Mainactivity. Handler = new handler (){
Public void handlemessage (Message MSG ){
String names = NULL;
String daxiaos = NULL;
String chicuns = NULL;
String times = NULL;
String xiangces = NULL;
String types = NULL;
If (msg. What = 1 ){
Names = msg. getdata (). getstring ("name ");
Daxiaos = msg. getdata (). getstring ("daxiao ");
Chicuns = msg. getdata (). getstring ("chicun ");
Times = msg. getdata (). getstring ("time ");
Xiangces = msg. getdata (). getstring ("xiangce ");
Types = msg. getdata (). getstring ("type ");
If (names! = NULL ){
Name. settext (names );
}
If (daxiaos! = NULL ){
Daxiao. settext (daxiaos );
}
If (chicuns! = NULL ){
Chicun. settext (chicuns );
}
If (times! = NULL ){
Time. settext (times );
}
If (xiangces! = NULL ){
Xiangce. settext (xiangces );
}
If (types! = NULL ){
Type. settext (types );
}
}
};
};
}
}
Below is
<? 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"
>
<Button
Android: Id = "@ + ID/showdailog"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "showdialog"
/>
</Linearlayout>
The following is the custom dialog. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "200dp"
Android: layout_height = "240dp"
Android: Orientation = "vertical"
Android: gravity = "center"
Android: padding = "20dp"
Android: Background = "#808080"
>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "name :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/name"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_horizontal"
Android: layout_margintop = "10dp"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Size :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/daxiao"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_horizontal"
Android: layout_margintop = "10dp"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Size :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/chicun"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_horizontal"
Android: layout_margintop = "10dp"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "shooting time :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/time"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_horizontal"
Android: layout_margintop = "10dp"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "album :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/xiangce"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
<Linearlayout
Android: Orientation = "horizontal"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_horizontal"
Android: layout_margintop = "10dp"
>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "type :"
Android: textstyle = "bold"
/>
<Textview
Android: Id = "@ + ID/type"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_marginleft = "20dp"
/>
</Linearlayout>
</Linearlayout>
OK, the above Code is complete,
Screenshot: