1. Use a view as the message prompt
Btn3.setonclicklistener (New button. onclicklistener (){
Public void onclick (view v ){
View view = inflateview (R. layout. View );
Textview txtmsg = (textview) view.findviewbyid(r.id.txt MSG );
Txtmsg. settext ("prompt content ");
Toast = new toast (main. This );
Toast. setview (View );
Toast. setduration (toast. length_long );
Toast. Show ();
}
});
2 status bar notification
Public void onclick (view v ){
// Instantiate the notification Manager
Icationicationmanager Nm = (notificationmanager) getsystemservice
(Notification_service );
// Specify the detailed notification page opened after clicking the notification (click the notification to open icationicationview
)
Pendingintent contentintent = pendingintent. getactivity (
Main. This, 0, new intent (main. This,
Icationicationview. Class), 0 );
// Instantiate a notification and specify its icon and title (displayed in the prompt bar)
Notification n = new notification (R. drawable. icon01, "I am rolling Notification Information
I am rolling notification information. I am rolling notification information ", system. currenttimemillis ());
// Set the notification sender and Notification Details (displayed in the notification list after the prompt bar is opened)
N. setlatesteventinfo (main. This, "Notification sender", "I am a detailed notification information, I am a detailed
Fine notification information I am the detailed notification information ", contentintent );
// After a delay of 100 milliseconds, the system vibrate for 250 milliseconds. After a pause of 100 milliseconds, the system then shakes for 500 milliseconds.
N. vibrate = new long [] {100,250,100,500 };
// Send a notification (the first parameter is the notification identifier)
Nm. 127y (0, N );
}
});
3. Image button:
Imagebutton imgbutton = (imagebutton) This. findviewbyid (R. Id. imagebutton );
// Set the background of the image button
Imgbutton. setbackgroundresource (R. drawable. icon01 );
4. image display:
Imageview imgview = (imageview) This. findviewbyid (R. Id. imageview );
// Specify the image to be displayed
Imgview. setbackgroundresource (R. drawable. icon01 );
5 checkbox:
Checkbox chk = (checkbox) This. findviewbyid (R. Id. CHK1 );
// Setoncheckedchangelistener ()-Response Check box selected status change event
Chk. setoncheckedchangelistener (New compoundbutton. oncheckedchangelistener (){
Public void oncheckedchanged (compoundbutton buttonview, Boolean ischecked ){
Textview TXT = (textview) _ checkbox. This. findviewbyid (R. Id. textview );
TXT. settext ("checkbox01 selected status:" + String. valueof (ischecked ));
}
});
6 togglebutton:
<! --
Togglebutton-double-state button control
Texton-text displayed when the button status is true
Textoff-text displayed when the button status is false
-->
<Togglebutton Android: Id = "@ + ID/togglebutton"
Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"
Android: texton = "Disable" Android: textoff = "open"/>
Final togglebutton BTN = (togglebutton) This. findviewbyid (R. Id. togglebutton );
// Setonclicklistener ()-click the event with the cursor of the response button
BTN. setonclicklistener (New button. onclicklistener (){
@ Override
Public void onclick (view v ){
Textview TXT = (textview) _ togglebutton. This. findviewbyid (R. Id. textview );
// Togglebutton. ischecked ()-button status of the two-State button
TXT. settext ("button status:" + String. valueof (BTN. ischecked ()));
}
});
7 progress bar:
<! --
Progress bar Control
Style-the style of the progress bar. In this example, the built-in style is used.
Max-maximum progress
SS-first progress position
Secondaryprogress-second progress position
-->
<Progressbar Android: Id = "@ + ID/progress_horizontal"
Style = "? Android: ATTR/progressbarstylehorizontal "Android: layout_width =" 200px"
Android: layout_height = "wrap_content" Android: max = "100"
Android: Progress = "50" Android: secondaryprogress = "75"/>
// Set features to allowProgramDisplay the progress bar (bar) on the title bar)
Requestwindowfeature (window. feature_progress );
// Set features to allow display of progress bars (circled) on the application title bar)
Requestwindowfeature (window. feature_indeterminate_progress );
This. setcontentview (R. layout. progressbar );
settitle ("progressbar");
// display the progress bar on the title bar.
setprogressbarvisibility (true );
// display the progress bar (circled) on the title bar
setprogressbarindeterminatevisibility (true );
// specify the progress of the progress bar
setprogress (50*100);
setsecondaryprogress (75*100);
9 seekbar:
seekbar-drag progress bar Control
MAX-maximum progress
progress-first progress position
secondaryprogress-second progress position
-->
Android: layout_height = "wrap_content" Android: max = "100"
Android: progress = "50" Android: secondaryprogress = "75"/>
mseekbar = (seekbar) findviewbyid (R. id. seekbar);
// setonseekbarchangelistener ()-responds to the drag progress bar event
mseekbar. setonseekbarchangelistener (this);
// The callback event when the progress changes after dragging the progress bar
Public void onprogresschanged (seekbar, int progress,
Boolean fromtouch) {
mprogresstext. settext (Progress + "%");
}
// Start to trace the touch before dragging the progress bar
Public void onstarttrackingtouch (seekbar ){
Mtrackingtext. settext ("start tracking touch ");
}
// Drag the progress bar and stop the tracking touch.
Public void onstoptrackingtouch (seekbar ){
Mtrackingtext. settext ("Stop tracking touch ");
}
10 zoom in and out controls:
Zoomcontrols = (zoomcontrols) This. findviewbyid (R. Id. zoomcontrols );
// Setonzoominclicklistener ()-responds to the event of clicking the zoom in button
Zoomcontrols. setonzoominclicklistener (New onclicklistener (){
Public void onclick (view v ){
Toast. maketext (_ zoomcontrols. This, "click the zoom in button ",
Toast. length_short). Show ();
}
});
// Setonzoomoutclicklistener ()-responds to the event of clicking the zoom out button
Zoomcontrols. setonzoomoutclicklistener (New onclicklistener (){
Public void onclick (view v ){
Toast. maketext (_ zoomcontrols. This, "click the zoom in button ",
Toast. length_short). Show ();
}
});
11 videoview:
videoview = (videoview) findviewbyid (R. id. videoview);
// specifies the address of the video to be played
videoview. setvideouri (URI. parse ("android. resource: // COM. webabcd. view/"+ R. raw. demo);
// videoview. setvideopath ();
// set the control bar of the player
videoview. setmediacontroller (New mediacontroller (this);
// start to play the video
videoview. start ();
12 tab control:
<! -- Content of Tab 1 -->
<Textview Android: Id = "@ + ID/view1" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" Android: text = "tab1 content"/>
<! -- Content of Tab 2 -->
<Textview Android: Id = "@ + ID/view2" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent" Android: text = "tab2 content"/>
// To implement the tab function, you must inherit tabactivity.
Public class _ tab extends tabactivity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. oncreate (savedinstancestate );
Tabhost = gettabhost ();
Layoutinflater. From (this). Inflate (R. layout. tab, tabhost. gettabcontentview (), true );
// Content of Tab 1
Tabhost. addtab (tabhost. newtabspec ("tab1 ")
. Setindicator ("tab1 ")
. Setcontent (R. Id. view1 ));
// Content of Tab 2 (with tab image set)
Tabhost. addtab (tabhost. newtabspec ("tab2 ")
. Setindicator ("tab2", getresources (). getdrawable (R. drawable. icon01 ))
. Setcontent (R. Id. view2 ));
// Content of tab 3 (set the content of tab to the specified activity)
Tabhost. addtab (tabhost. newtabspec ("tab3 ")
. Setindicator ("tab3 ")
. Setcontent (new intent (this, _ textview. Class )));
}
}
13 gallery thumbnail components:
<! --
Gallery-thumbnail browser control
Spacing-spacing between thumbnails In the thumbnail list
-->
<Gallery Android: Id = "@ + ID/Gallery" Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" Android: spacing = "20px"/>
Gallery gallery = (Gallery) findviewbyid (R. Id. Gallery );
// Specify an adapter for the thumbnail Browser
Gallery. setadapter (New imageadapter (this ));
// Response to the event after a thumbnail is selected on the thumbnail list
Gallery. setonitemselectedlistener (New adapterview. onitemselectedlistener (){
@ Override
Public void onitemselected (adapterview <?> Parent, view V,
Int position, long ID ){
Toast. maketext (_ gallery. This, String. valueof (position), Toast. length_short). Show ();
}
@ Override
Public void onnothingselected (adapterview <?> Arg0 ){
}
});
}
// Inherit the baseadapter for custom image adapters
Public class imageadapter extends baseadapter {
Private context mcontext;
Public imageadapter (context ){
Mcontext = context;
}
Public int getcount (){
Return mthumbids. length;
}
Public object getitem (INT position ){
Return position;
}
Public long getitemid (INT position ){
Return position;
}
Public View getview (INT position, view convertview, viewgroup parent ){
Imageview image = new imageview (mcontext );
Image. setimageresource (mthumbids [position]);
Image. setadjustviewbounds (true );
Image. setlayoutparams (new gallery. layoutparams (
Layoutparams. wrap_content, layoutparams. wrap_content ));
Return image;
}
}
// Set of images to be displayed
Private integer [] mthumbids = {R. drawable. icon01, R. drawable. icon02,
R. drawable. icon03, R. drawable. icon04, R. drawable. icon05 };