Layoutinflater usage and progressdialog usage in Android

Source: Internet
Author: User

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 );
}
});

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.