导航抽屉中的ListView DrawerLayout未填充

时间:2014-12-07 22:09:57

标签: android listview navigation-drawer

DrawerLayout activity_register.xml

<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">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal|center"
android:orientation="vertical" >    
<TextView 
  android:id="@+id/msgView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_weight="1" />
  <LinearLayout
  android:id="@+id/sitrep_buttons_layout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:gravity="center_vertical|center_horizontal|center"
  android:orientation="vertical">
  <ImageView
      android:id="@+id/sitrep_image"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
      android:visibility="gone"
      android:contentDescription="@string/desc"/>
  </LinearLayout>
</LinearLayout>
<ListView android:id="@+id/left_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="#999"/>
</android.support.v4.widget.DrawerLayout>

在我的oncreate(Bundle savedInstanceState)

     private ListView mDrawerList;
  private String[] mActivities;

  private String username = "";

  @Override
  public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

// mDrawerList = new ListView(RegisterActivity.this);

mActivities = getResources().getStringArray(R.array.menu_item_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerList.setBackgroundColor(0xFF00FF00);
Log.d(DTAG, "mDrawerList.getContentDescription: "+mDrawerList.getContentDescription());
Log.d(DTAG, "mDrawerList "+mDrawerList.equals(null));
Log.d(DTAG, "mActivities.length: "+mActivities.length);
for(int i = 0; i < mActivities.length; i++){
    Log.d(DTAG, "mActivities: "+mActivities[i]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, mActivities);
Log.d(DTAG, "adapter.getCount: "+adapter.getCount());
mDrawerList.setAdapter(adapter);

日志显示我的阵列已正确填充。 导航抽屉left_drawer(ListView)显示但未填充。如果我更改layout_width,则宽度会更改,并且背景颜色也会匹配设置。我一直在查看多个帖子来比较我的代码,但我看不到代码的问题。

任何想法都会很棒!

好的,这里有一些东西。我无法以编程方式更改ListView的任何属性。

mDrawerList.setBackgroundColor(0xFF00FF00);

无效。背景仍然设置为布局文件中的设置。

0 个答案:

没有答案