Search code examples
androidslidingdrawer

Error inflating class android.widget.SlidingDrawer


I ran up against a few problems when i use Slidingdrawer. How to fix it.

Main XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@color/white">
    <SlidingDrawer 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@color/black"
    android:handle="@+id/handle"
    android:id="@+id/slideD">
    <Button 
        android:layout_width="60dp" 
        android:layout_height="60dp" 
        android:id="@id/handle" 
        android:background="@drawable/arrow_up"
        />
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
              <Button 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:background="@drawable/ic_launcher"
            >
          </Button>
          <Button 
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:background="@drawable/ic_launcher"
            >
          </Button>     
        </LinearLayout>
    </SlidingDrawer>
</LinearLayout>

Activity

public class ATDTActivity extends Activity {

    SlidingDrawer slideD;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        slideD = (SlidingDrawer)findViewById(R.id.slideD);
        slideD.setOnDrawerOpenListener(new OnDrawerOpenListener(){
            @Override
            public void onDrawerOpened() {
            slideD.getHandle().setBackgroundResource(R.drawable.arrow_down);
            }
        });
        slideD.setOnDrawerCloseListener(new OnDrawerCloseListener(){
            @Override
            public void onDrawerClosed() {
            sideD.getHandle().setBackgroundResource(R.drawable.arrow_up);
                    }
        });
    }
}

Thank for help!. Your post does not have much context to explain the code sections; please explain your scenario more clearly.


Solution

  • Add content to SlidingDrawer:

    ....
    <SlidingDrawer
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:content="@+id/content"
            android:handle="@+id/handle"
            android:id="@+id/slideD">
     ........
     <LinearLayout
                android:id="@id/content"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
    
      .......