Reputation: 3865
I created an LinearLayout using the following code:
LayoutInflater inflater = getLayoutInflater();
LinearLayout container = (LinearLayout) inflater.inflate(R.layout.my_item, null);
My question is, is container.getId() equal to 'R.layout.my_item' after the code above is executed? Or, do I have to set id to the newly created layout using the code below?
container.setId(R.layout.my_item);
My example code showed that I have to explicitly set id to the layout created from code, which is out of my expectation.
Thanks.
Edit: The purpose that I want to set id on the layout is for OnClick listener set on the layout.
public void onClick(View v) {
Intent intent;
switch (v.getId()) {
case R.layout.my_item:
....
break;
Upvotes: 3
Views: 2291
Reputation: 11904
The id would be the id of the view you inflated. That is to say, whatever the android:id
of the root element of R.layout.my_item
is. It should be an R.id value, not a R.layout one.
Upvotes: 3