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.
You can also set the visibility in your layout. xml if you want it hidden when your application first starts. android:visibility="gone" should do the trick. This way it is hidden from the very start when the layout is initialized by your app.
To efficiently reuse complete layouts, you can use the <include/> and <merge/> tags to embed another layout inside the current layout. Reusing layouts is particularly powerful as it allows you to create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With