这是我的活动onCreate
函数,我想在Drawer中向Listview添加数据
数据添加成功,但当我尝试添加抽屉时,抽屉中没有数据显示,
Logcat没有显示错误。
DrawerLayout dLayout;
ListView drawer_list;
String[] menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//mySchedule=new Schedule();
setContentView(R.layout.activity_main);
menu = new String[]{"Home","Android","Windows","Linux","Contact Us"};
dLayout=(DrawerLayout) findViewById(R.id.drawer_layout);
drawer_list=(ListView) findViewById(R.id.list_drawer);
ArrayAdapter adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,menu);
if(adapter!=null){
drawer_list.setAdapter(adapter);
}else{
System.out.print("adapter emepty");
}
drawer_list.setSelector(android.R.color.holo_blue_dark);
drawer_list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,""+position, Toast.LENGTH_LONG).show();
}
});
}
这是布局抽屉布局文件.........
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg015"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:orientation="vertical" >
<TextView
android:id="@+id/tvEvents"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#555555"
android:text="Today's Events"
android:textColor="#aaaaaa"
android:textSize="18sp" />
<ListView
android:id="@+id/scheduleView"
android:layout_width="fill_parent"
android:layout_below="@+id/tvEvents"
android:layout_height="209dp" />
<TextView
android:id="@+id/tvClasses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/scheduleView"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:fitsSystemWindows="false"
android:text="Today's Classes"
android:textColor="#aaaaaa"
android:background="#555555"
android:textSize="18sp" />
<ListView
android:id="@+id/classesView"
android:layout_below="@+id/tvClasses"
android:layout_width="fill_parent"
android:layout_height="210dp" />
<TextView
android:id="@+id/tvTasks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/classesView"
android:text="Today's Task"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:textColor="#aaaaaa"
android:background="#555555"
android:textSize="18sp" />
<ListView
android:id="@+id/taskView"
android:layout_below="@+id/tvTasks"
android:layout_width="fill_parent"
android:layout_height="210dp"
/>
</RelativeLayout>
</ScrollView>
<ListView
android:id="@+id/list_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#fff"/>
</android.support.v4.widget.DrawerLayout>
抽屉打开时没有任何数据!