Referencing a View in another XML file
I have a ListView in a file called a.xml.
<ListView
        android:id="@+id/mylistview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scrollbars="none"
        android:layout_above="XYZ"
        />
In a.xml, I also include another file called b.xml.
<include android:id="@+id/bottombar" layout="@layout/b" />
For one of the settings of the ListView, I want to reference an id (XYZ) that exists in b.xml.
Is there a way I can do this?
I've tried the following:
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <include android:id="@+id/bottombar" layout="@layout/b" />
    <ListView
        android:id="@+id/mylistview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:scrollb开发者_开发问答ars="none"
        android:layout_above="@id/bottombar_background"
        />
</RelativeLayout>
Where @id/bottombar_background exists in @layout/b, but Eclipse throws "no resource" errors at me.
After you have used setContentView(R.layout.a) you should be able to use findViewById(R.id.my_id_in_b).
Use this syntax: android:layout_toLeftOf="@+id/my_id_from_b". It prevents any reference issues.
The plus in this instance tells the compiler to do a second pass on the layout, looking for that id on the second time through. Try it out - I know it works, as I use this syntax all the time.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论