View id after bloat

I created 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 executing the above code? Or do I need to set the id for the newly created layout using the code below?

container.setId(R.layout.my_item);

My sample code showed that I should explicitly set the id to a layout created from code that does not meet my expectations.

Thank.

Edit: The goal I want to set the id on the layout is the OnClick listener installed on the layout.

public void onClick(View v) {
    Intent intent;

    switch (v.getId()) {

    case R.layout.my_item:
      ....
    break;
+3
source share
2 answers

The identifier will be the identifier of the bloated view. That is, regardless of the android:idroot element R.layout.my_item. This should be the value of R.id, not R.layout.

+3
0

Source: https://habr.com/ru/post/1795329/


All Articles