2

I have similar problem like this thread findViewById returns null on a LinearLayout inside an <include>d view

I have similar problem:

xml that calls the include block:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            ...>
    <include  
                android:id="@+id/popupMenu"
                layout="@layout/mainmenu_popup" /> 
    </RelativeLayout>

and mainmenu_popup.xml that contains the included code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:visibility="gone"
        android:layout_marginTop="@dimen/action_bar_height"
        android:layout_width="0dp"
        android:layout_height="0dp">
      <fragment
        android:id="@+id/mainmenupopup_fragment"
        class="RetailMobile.MainMenuFragment" />
    <TextView
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_below="@id/mainmenupopup_fragment" 
            android:background="@color/dark_blue"
            android:id="@+id/blueLine" />
    <RelativeLayout
        ...
    </RelativeLayout>
</RelativeLayout>

I follow Luksprog's answer

RelativeLayout popupMenu = this.Activity.FindViewById<RelativeLayout>(Resource.Id.popupMenu);

but popupMenu == null

i also checked this thread findViewById not working for an include? with no positive result.

Community
  • 1
  • 1

2 Answers2

2

add android:id to RelativeLayout in mainmenu_popup.xml and then find view by id defined there

Dmitry Guselnikov
  • 1,048
  • 1
  • 8
  • 21
0

I found the solution mainmenu_popup.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_mainmenu">
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/popup_mainmenu_inner"> ...

then i refer to popup_mainmenu_inner:

 this.Activity.FindViewById<RelativeLayout>(Resource.Id.popup_mainmenu_inner);
  • not so happy so far because i found that if my parent container is Fragment(where i `call FindViewById(Resource.Id.popup_mainmenu_inner)`) it is still null, only works if parent container is FragmentActivity or Activity – Mariyan Marinov Jun 18 '13 at 12:46