In actual developmentLayoutinflaterThis class is very useful, and its function is similar to findviewbyid (). The difference is that layoutinflater is used to find and instantiate XML layout files under Res/layout/, while findviewbyid () is to find the specific widget controls (such as button and textview) under the XML layout file ).
Specific functions:
1. layoutinflater must be used for an interface that is not loaded or needs to be dynamically loaded. inflate () to load;
2. For a loaded interface, you can use the activiyt. findviewbyid () method to obtain the interface elements.
There are three methods for use:
// layoutinflater Inflater = layoutinflater. from (context);
// layoutinflater Inflater = getlayoutinflater ();
layoutinflater Inflater = (layoutinflater) getsystemservice (layout_inflater_service);
Please refer to the following detailsCode: Note: In the oncreate method
Button BTN = New Button ( This );
BTN. settext ("click to load ");
// Layoutinflater Inflater = layoutinflater. From (this );
// Layoutinflater Inflater = getlayoutinflater ();
Layoutinflater Inflater = (layoutinflater) getsystemservice (layout_inflater_service );
Relativelayout view = (relativelayout) Inflater. Inflate (R. layout. activity_main, Null );
View. addview (BTN );
Setcontentview (View); // set the current layout VI EW
Progressdialog usage:
There are two types: 1. Override oncreatedialog in activitiy,
HoweverWhen calling, use the showdialog (0);
Public Dialog oncreatedialog ( Int ID ){
Progressdialog Pd = New Progressdialog ( This );
PD. settitle ("progress bar "); // Set title
PD. setcancelable ( True ); // Set whether to cancel by pressing the rollback key
PD. setindeterminate ( True ); // Set to ambiguous
PD. setmessage ("running ..."); // Set content
Return PD;
}
2. directly create
BTN. setonclicklistener ( New Onclicklistener (){
@ Override
Public Void Onclick (view v ){
// Todo auto-generated method stub
// Showdialog (0 );
Progressdialog. Show (mainactivity. This , "Progress bar", "loading... please wait ...",True , True );
}
});