Question

trying to open and close slidedrawer with one button but its not work

the xml code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/open_close_slide"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/setting" />

<SlidingDrawer
    android:id="@+id/slidingDrawer1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:content="@+id/content"
    android:handle="@+id/handle" >

    <Button
        android:id="@+id/handle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Handle" />

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </LinearLayout>
</SlidingDrawer>

the java code

  final SlidingDrawer slidingDrawer1 = (SlidingDrawer) findViewById(R.id.slidingDrawer1);

    Button setting = (Button) findViewById(R.id.open_close_slide);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            slidingDrawer1.open();
        // want to add another code here to close the slide 
        }
    });

how to make this button work with double click in the first click open the slide and in the second click close the slide ?

Was it helpful?

Solution

final SlidingDrawer slidingDrawer1 = (SlidingDrawer) findViewById(R.id.slidingDrawer1);

    Button setting = (Button) findViewById(R.id.open_close_slide);
    setting.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            if (slidingDrawer1.isOpened()){
               slidingDrawer1.close();
            } 
            else{
               slidingDrawer1.open();    
            }

        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top