简体   繁体   中英

ANDROID - ListView appear on button click

I want create a ListView on a fragment.

That ListView must be "hide" and only appear when I clik a button.

Attached pictures of what I need know.

MENU1

MENU2

菜单3

  1. If I click on center button (the arrow button) a ListView appear from bottom.

  2. If I click again the arrow button a ListView hide again.

I dont need open new Activity, I need that ListView on the same Activity but I dont know how I can show ListView and Hide .

Can you help me for that?

You need to use MotionEvent

Create a class by entending SimpleOnGestureListener . You can find tutorial here

Reference from this Drawer Demo Project on GitHub
You can use the class MultiDirectionSlidingDrawer.java and include the ListView in a separate layout which will act as the container of what is going to slide up.

In your Activity , suppose the content view is: main_layout
ie setContentView(R.layout.main_layout);

Then include the drawer in your main_layout like:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        arrow to open />

    <package.MultiDirectionSlidingDrawer
        xmlns:my="http://schemas.android.com/apk/res/yourpackageforslider"
        android:id="@+id/drawer"
                //here you specify the direction  
        my:direction="bottomToTop"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        my:handle="@+id/handle" //this is the button -arrow
        my:content="@+id/content" -content (which would identify your listview layout)>
        <include
            android:id="@id/content"
            layout="@layout/layoutContainingYourListview" />
        <ImageView
            android:id="@id/handle"
            button for it to push it up/down />
    </package.MultiDirectionSlidingDrawer>
</RelativeLayout>  

Your listView would remain completely independent of the code above and in a different layout -- layoutContainingYourListview. This is good as the drawer sliding up becomes irrespective of its content - which you can change and work with dynamically too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM