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