Android 滑动抽屉不工作

Android 滑动抽屉不工作,android,listener,slidingdrawer,Android,Listener,Slidingdrawer,在我的应用程序中,我实现了滑动抽屉,但它不工作。我在任何地方都错了 Drawer = (SlidingDrawer) findViewById(R.id.drawer); Drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() { @Override public void onDrawerOpened() { Toast.makeText(getApplicatio

在我的应用程序中,我实现了滑动抽屉,但它不工作。我在任何地方都错了

Drawer = (SlidingDrawer) findViewById(R.id.drawer);


    Drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {

        @Override
        public void onDrawerOpened() {
            Toast.makeText(getApplicationContext(),"Drawer Opened", Toast.LENGTH_SHORT).show();             
        }
    });
类似地,
setOnDrawerCloseListener
也不工作,我的XML文件是:

<SlidingDrawer android:id="@+id/drawer"
        android:background="@null" android:layout_height="fill_parent"
        android:handle="@+id/handle" android:content="@+id/chat_history_container"
        android:layout_width="fill_parent">
        <ImageView android:id="@+id/handle" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:src="@drawable/chat_icon" />

        <RelativeLayout android:id="@+id/chat_history_container"
            android:layout_width="fill_parent" android:layout_height="wrap_content">
            //Some TextViews here

        </RelativeLayout>
</SlidingDrawer>

//这里有一些文本视图
尝试以下代码: Xml代码:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:gravity="bottom"         
    android:background="@drawable/androidpeople">
<SlidingDrawer android:layout_width="wrap_content" 
    android:id="@+id/SlidingDrawer"     
    android:handle="@+id/slideHandleButton"   android:content="@+id/contentLayout"    
    android:padding="10dip" android:layout_height="250dip">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"   
    android:id="@+id/slideHandleButton" android:background="@drawable/closearrow">
</Button>
<LinearLayout android:layout_width="wrap_content" android:id="@+id/contentLayout" android:orientation="vertical" android:gravity="center|top" android:padding="10dip" android:background="#C0C0C0" android:layout_height="wrap_content">
<Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>
<Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Content"></Button>

请查看此链接以供参考…

@Venkatesh:我们的代码和我的代码没有区别。。我也用了你给我的同样的参考资料…它会有用的它对我有用。。在Log cat中出现了什么错误?我解决了这个问题,而不是Toast消息中的“getApplicationContext()”,而是将“YouActivityName.this”。。你是对的,谢谢你的帮助。
public class slidingDrawerExample extends Activity {
 Button slideHandleButton;
 SlidingDrawer slidingDrawer;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  slideHandleButton = (Button) findViewById(R.id.slideHandleButton);
  slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
   slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
@Override
public void onDrawerOpened() {
    slideHandleButton.setBackgroundResource(R.drawable.openarrow);
}
});
    slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
     @Override
  public void onDrawerClosed() {
    slideHandleButton.setBackgroundResource(R.drawable.closearrow);
}
 });
 }
}