Inflate () and findViewById (), findviewbyid

Source: Internet
Author: User

Inflate () and findViewById (), findviewbyid

1. findViewById () is the method of the View object. First, you can obtain the View through the inflate () method and call the getViewById () method of the View object to obtain the subview on The View tree.

2. The inflate () function can be obtained through the getSystemService () method. The parameter is LAYOUT_INFLATER_SERVICE.

3. The first parameter of the inflate () function is the R reference of the layout file, and the second parameter is the root ViewGroup, that is, the rendering starts from which ViewGroup node. For the second parameter, You need to instantiate this VIewGroup. You can do this by setting the root id in the XML layout file and then using the findViewById () method to get it through id. For example

  • View layout = inflater. inflate (R. layout. toast_layout, (ViewGroup)
  • FindViewById (R. id. toast_layout_root ));


Android findViewByid Method

Cannot obtain buttonB

Thank you! What is the Null Pointer Error reported by Viewinflate?

Actually solved the problem of using an adapter. I just wanted to get a progressbar list, now, I can do a lot of things. Hey, the default style of android new progressbar is what reflection mechanism is mentioned on the circular network to change a certain attribute to achieve this. I think this is very troublesome for beginners like me. method. addView (txt, params); View view = View. inflate (context, R. layout. bookprogressbar, null); if (view. findViewById (R. id. bookprogressbar) instanceof ProgressBar) {progressbar = (ProgressBar) view. findViewById (R. id. bookprogressbar); progressbar. setTag (xxxxx); progresslist. add (progressbar); progressbar. setProgress (Integer. parseInt (xxxxx); map. put ("progressbar", progressbar); linear. addView (view, params );}

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.