Hide included layout in android
12,717
Solution 1
you should change
footertabs = (RelativeLayout) findViewById(R.id.footertab);
footer_tabs = (RelativeLayout) findViewById(R.id.footer_tab);
with
footertabs = (RelativeLayout) findViewById(R.id.footer);
footer_tabs = (RelativeLayout) findViewById(R.id.footer1);
Solution 2
Well it appears to me that you're using the wrong id's. You're getting a null pointer somewhere (I'm not sure where because there are no line numbers), but I see in your xml you have id's, footer
and footer1
, but in your code you are trying to find elements with id's footertab
, and footer_tab
. You should make these id's match.
Author by
user2218667
Updated on June 04, 2022Comments
-
user2218667 almost 2 years
I have to develop an android application.
I have created one layout file that uses another layout file using the
include
tag.<include android:id="@+id/footer" android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" layout="@layout/footer_tabs" /> <include android:id="@+id/footer1" android:layout_width="match_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" layout="@layout/footertabs" />
I would like to show the included layout when a response is null, otherwise I would like to hide the layout and show the other. Here is what I have so far:
footertabs = (RelativeLayout) findViewById(R.id.footertab); footer_tabs = (RelativeLayout) findViewById(R.id.footer_tab); if (Constants.response==null) { footertabs.setVisibility(View.VISIBLE); footer_tabs.setVisibility(View.GONE); } else { footertabs.setVisibility(View.GONE); footer_tabs.setVisibility(View.VISIBLE); }
But I'm getting the following error:
07-15 17:19:09.893: E/AndroidRuntime(15143): Caused by: java.lang.NullPointerException 07-15 17:19:09.893: E/AndroidRuntime(15143): at com.example.androidbestinuk.HomePage.onCreate(HomePage.java:56)
Please help me debug this error.