0

Is it possible to find a view by id if it's an ?:

<LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" >

    <include
      android:id="@+id/foo"
      layout="@layout/test" />

  ...

View view = findViewById(R.id.foo);

What is "view" in this case? Is it a view? Does it resolve to whatever the top-level element of "layout/test" is?

Thanks

user291701
  • 38,411
  • 72
  • 187
  • 285

2 Answers2

1

You're essentially overwriting the ID of the top-parent view in the layout your including, so what you'll get is the top-view of the entire layout and it's contents. The <include> tag is, in effect, a copy-and-paste of the contained layout. You can override the id tag and any attribute with layout_.

DeeV
  • 35,865
  • 9
  • 108
  • 95
  • Should the returned view work ok with View.setVisibility()? Debugging this now, but seems like once I do findViewById(). calling view.setVisibility(View.GONE) has no effect? – user291701 Feb 07 '12 at 21:35
  • I have never tried that, but I assume it should work. Every time I've used the tag, I've been able to use it normally for most things. However, the `visible` property is not one of the ones you can overwrite in xml, so it may not be allowed in this case. – DeeV Feb 07 '12 at 21:37
  • Yes, you can change the visibility of Views brought in through `include`. – Brian Dupuis Feb 07 '12 at 22:18
0

foo will be the id of the root element (ViewGroup or View) of test layout. If an id is already defined for it in test layout foo will override it.

dmaxi
  • 3,267
  • 1
  • 18
  • 15