1

in my application layout, i have a setting button....when we push it, it will show some sub menus....when we push it again, it will hide all sub menus....look like expandable listview, but not exactly like that....just hiding/unhiding menu in order to get some space for another views....how can i do that?

here is the screenshots that exactly what i want to do

hide menu

unhide menu

here is my xml file:

<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
    <EditText
        android:id="@+id/Editsearch"
        android:hint="Enter keyword..."
        android:layout_alignParentLeft="true"
        android:singleLine="true"
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@+id/search"
        android:layout_height="wrap_content" />
    <ImageButton
        android:id="@+id/search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/button_search"
        android:layout_alignParentRight="true" />
    <Spinner
        android:id="@+id/province"
        android:layout_width="135dp"
        android:layout_height="45dp"
        android:layout_below="@+id/Editsearch"
        android:layout_toLeftOf="@+id/setting"
        android:textSize="12dip"
        android:textStyle="bold"
        android:background="@android:drawable/btn_default"
    />
    <ImageButton
        android:id="@+id/setting"
        android:layout_width="wrap_content"
        android:layout_height="45dip"
        android:layout_below="@+id/Editsearch"
        android:src="@drawable/button_setting"
        android:layout_alignParentRight="true" />
    <Spinner
        android:id="@+id/Category"
        android:layout_width="135dp"
        android:layout_height="45dp"
        android:text="Category"
        android:layout_below="@+id/Editsearch"
        android:layout_alignParentLeft="true"
        android:background="@android:drawable/btn_default" />
        <!-- Job Category title-->
    <TextView
        android:id="@+id/Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:typeface="serif"
        android:textSize="13dip"
        android:layout_below="@+id/province"
        android:layout_gravity="center"

        android:text="Total Job : 1982"
        android:textStyle="bold" />
    <ListView
        android:id="@+id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Title"
        android:listSelector="@drawable/list_selector" />
</RelativeLayout>

thank in advance

EdgarT
  • 1,080
  • 11
  • 18
Arsyah
  • 79
  • 3
  • 11

2 Answers2

1

It is very simple. Just place those 3 buttons in a layout and set the visibility of that layout to gone/visible on click of hide/unhide button.

EDIT :

It will be like put your spinners which you like to hide/unhide in a layout and provide an ID for it.

<ImageButton
        android:id="@+id/setting"
        android:layout_width="wrap_content"
        android:layout_height="45dip"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/Editsearch"
        android:src="@drawable/button_setting" />

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    **android:id="@+id/submenu_layout"**
    android:layout_below="@+id/Editsearch"
    >
    <Spinner
        android:id="@+id/category1"
        android:layout_width="135dp"
        android:layout_height="45dp"
        android:layout_alignParentLeft="true"
        android:background="@android:drawable/btn_default"
        android:text="Category" />
    <Spinner
        android:id="@+id/category2"
        android:layout_width="135dp"
        android:layout_height="45dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/category1"
        android:background="@android:drawable/btn_default"
        android:text="Category" />
    <Spinner
        android:id="@+id/category3"
        android:layout_width="135dp"
        android:layout_height="45dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/category2"
        android:background="@android:drawable/btn_default"
        android:text="Category" />
    </RelativeLayout>

Then use this id to take the reference of this layout in your code.

RelativeLayout submenuLayout = (RelativeLayout) findViewById(R.id.submenu_layout);

EDIT 2:

After that OnClick of setting imageButton :

 if(submenuLayout .getVisibility() == View.VISIBLE)
    submenuLayout .setVisibility(View.GONE);
    else
        submenuLayout .setVisibility(View.VISIBLE);
Sourab Sharma
  • 2,940
  • 1
  • 25
  • 38
  • thank for the answer.... but, can you show me the example codes? i'm a newbie in android programming...:D – Arsyah Feb 06 '13 at 09:59
  • Thanks... after seeing your xml file ... an advice to every newbie... do follow coding conventions definitely... it will make your life easy on the road ahead.. – Sourab Sharma Feb 06 '13 at 10:37
  • Hi Mr.Sourab Sharma.....one more question...:D i'm still got a little problem here....in my xml file i used (android:visibility="gone") in submenuLayout, then in onclick listener in my activity i used "submenuLayout.setVisibility(View.VISIBLE);". when i push the setting button, it show the hidden layout, but when i push it once again, nothing happen....i wanna hide the layout again....how to do that.... thank in advance – Arsyah Feb 07 '13 at 02:42
  • I have edited my answer again... please see EDIT 2 for your solution to this issue. – Sourab Sharma Feb 07 '13 at 05:42
  • hi Mr.Sourab Sharma, i have a problem with my app, please check this [LINK](http://stackoverflow.com/questions/15376995/getting-next-and-previous-detail-data-from-listview) , hope you can help me....:) – Arsyah Mar 13 '13 at 08:17
0

use this code

to make it visible on button click

themeUrlRow.setVisibility(View.VISIBLE);

to make it invisible

themeUrlRow.setVisibility(View.GONE);

and in xml put the button in a layout and also make it invisible and in on clicklistener add the above code.

xml code

            <LinearLayout
               android:id="@+id/themeUrlRow"
            android:layout_width="fill_parent"
            android:gravity="center"
            android:visibility="gone" > />

            <Button
                android:id="@+id/register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Register" />

            <Button
                android:id="@+id/register"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Register" />
        </LinearLayout>
onkar
  • 4,427
  • 10
  • 52
  • 89
saran
  • 461
  • 1
  • 6
  • 20