Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide included layout in android

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.

like image 900
user2218667 Avatar asked Jul 15 '13 11:07

user2218667


People also ask

How do you hide layout?

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.

What is include in Android layout?

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.


1 Answers

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);
like image 78
Blackbelt Avatar answered Oct 09 '22 15:10

Blackbelt