public class MyInflate extends Activity {
private TextView tv;
public void OnCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
LayoutInflater inflate = LayoutInflater.from (this);
View view = inflate.inflate (R.layout.main, null);
setContentView (View);
}
}
behind inflate function that argument is null, after reading official documents still do not understand what it means if a ViewGroup, can give an example of it<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Top
Reply:
public View inflate (int Resourece, ViewGroup root)
reSource: View the layout of the ID
root: root view
generated hierarchyreturn filled root view hierarchy. If the parameter provides root, then root is the root view; otherwise filled root is the root view XML documents.
mail.xml file hierarchy is such
If I use the function
View view = inflate.inflate (R.layout.main, (ViewGroup) findViewById (R.id.LinearLayout02));
This is not LinearLayout02 corresponds become root view, use view.findViewById can not find the id of the TextView tv1 of it.
I tried it in fact is not the case, you can still find it. inflate the second parameter set this function in the end what use is it
Reply:
The second parameter, you get after you instantiate view is a child view this viewgroup
Reply:
View view = inflate.inflate (R.layout.main, (ViewGroup) findViewById (R.id.LinearLayout02)); you this second argument is null. . . So the view is not attached to a separate any groupview below.
Reply:
How to write as the second parameter will be empty yet. . . There LinearLayout02 of XML, how can it not be empty, can give an example of it
Reply:
That's because you go from the current view, and you did not generate the current view, of course, be found. setContentView (view), the only view of the current activity, and that the code you are actually looking inside from view.
View view = inflate.inflate (R.layout.main, null)
setContentView (View);
View new = inflate.inflate (R.layout.main, (ViewGroup) findViewById (R.id.LinearLayout02))
So as to not null.
Reply:
Oh, right,
View new = inflate.inflate (R.layout.main, (ViewGroup) findViewById (R.id.LinearLayout02))
But I later wrote the program tx1 = (TextView) view2.findViewById (R.id.tv1)
Can still be found, but is not LinearLayout02 tx1 following is LinearLayout01 below
Reply:
That is because there R.layout.main Yeah,
Reply:
That should not bar View findViewById function should only be looking for the right child, tv1 not his child
Reply:
I come and take points points, do not mind
Reply:
Go top
Reply:
Top
Reply:
You are juxtaposed relationship several layouts, there is no parent-child hierarchy, you put tv1 into LinearLayout01 inside can not get to try again.
Reply:
Does get confused,
Reply:
Although not fully resolved, or thank you with ideas, understand a lot
Reply:
Reply:
Still do not understand these two parameters?
Reply:
inflate (int Resourece, ViewGroup root) their relationship?
Reply:
inflate (int Resourece, ViewGroup root)?
Reply:
Understand, the top one
No comments:
Post a Comment