Reputation: 45
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.
Upvotes: 2
Views: 1327
Reputation: 45
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);
Upvotes: 0
Reputation: 1046
add android:id
to RelativeLayout in mainmenu_popup.xml and then find view by id defined there
Upvotes: 2