我遇到这种错误,在搜索可能的资源后仍然无效。
错误:
java.lang.IllegalArgumentException: View android.widget.ExpandableListView{416b0bc8 VFED.VC. ......ID 0,0-480,0 #7f080005 app:id/lvExp} is not a drawer
继承我的代码:
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
private DrawerLayout drawer;
private LinearLayout linear;
Button btn;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prepareListData();
btn = (Button)findViewById(R.id.button1);
linear = (LinearLayout)findViewById(R.id.linear);
expListView = (ExpandableListView) findViewById(R.id.lvExp);
drawer = (DrawerLayout)findViewById(R.id.drawer_layout);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(!drawer.isDrawerOpen(expListView))
{
drawer.openDrawer(expListView);
}
else
{
drawer.closeDrawer(expListView);
}
}
});
// get the listview
// preparing list data
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
FOR 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="#f4f4f4" >
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#000000"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="47dp"
android:layout_height="45dp"
android:background="@drawable/ic_home" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Drawer"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ExpandableListView
android:id="@+id/lvExp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000" >
</ExpandableListView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
</LinearLayout>