2014-10-01 63 views
0

我创建了一个简单的SliderDrawer。当点击手柄时,它会正确打开,但再次单击时不会关闭。我在类上设置了onclick,因此当单击该句柄并且滑动拉链打开时,它会关闭但不起作用。任何想法为什么请?Slidingdrawer not closing

Slider.java

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.SlidingDrawer; 

@SuppressWarnings("deprecation") 
public class Slider extends Activity { 

    SlidingDrawer sd; 
    Button handler; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.sliding); 
     sd = (SlidingDrawer) findViewById(R.id.slidingD); 
     handler = (Button) findViewById(R.id.handle); 
     handler.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if(sd.isOpened() == true){ 
        sd.animateClose(); 
       } 
      } 
     }); 
    } 
} 

sliding.xml

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

    <SlidingDrawer 
     android:id="@+id/slidingD" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:content="@+id/content" 
     android:handle="@+id/handle" > 
     <!-- android:handle calls the button (Handle) --> 
     <!-- android:content calls the linear layout (Hidden Content) --> 

     <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" > 

      <CheckBox 
       android:id="@+id/cSlideable" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="CheckBox" /> 
     </LinearLayout> 
    </SlidingDrawer> 

</LinearLayout> 
+0

也许有相同的按钮id和句柄不是一个好主意? – Blackbelt 2014-10-01 10:18:02

+0

从我的理解是,该按钮是滑动拉手的处理程序。如果我错了,请纠正我。 – wayzz 2014-10-01 10:22:31

+0

我的确是一个问题。 – Blackbelt 2014-10-01 10:24:50

回答

0

我做了什么,使其工作设置

handler.OnClickListener

(本)

和所用的override的onClick方法

@Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     switch (v.getId()) { 
     case R.id.handle: 
      sd.close(); 
      break; 
     } 
    }