findViewById not working for an include?

后端 未结 7 1184
终归单人心
终归单人心 2020-11-27 06:05

I have an include like:


The include layout looks like (te

相关标签:
7条回答
  • 2020-11-27 06:29

    Try retrieving the <include /> and then searching within that

    Make sure your root has the same ID as the root element in the included XML file.. ex

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

    Then retrieve your "inner" content using:

    FrameLayout outer = (FrameLayout)findViewById(R.id.outer);
    
    ImageView iv = (ImageView)outer.findViewById(R.id.inner);
    if (iv == null) {
        Log.e(TAG, "Not found!");
    }
    
    0 讨论(0)
提交回复
热议问题