2013-10-02 44 views
0

我有一個顯示ListView的活動屏幕。這個ListView允許用戶選擇他們心中的內容。我沒有問題。導航抽屜中的ListView無法以視覺顯示選擇

但是,屏幕上還有一個導航抽屜。在那是另一個ListView。我已手動設置其中一個項目以供選擇/檢查。但是,當導航抽屜打開時,該ListView中不會出現任何視覺效果。如果我以編程方式查詢它,我被告知一個項目被檢查,它的位置是我所期望的。

我做錯了什麼?

我對屏幕的XML看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/NavigationDrawerLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ListView 
     android:id="@+id/folderList" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:choiceMode="singleChoice" 
     android:listSelector="@android:color/darker_gray" /> 
    <LinearLayout 
     android:id="@+id/drawerView" 
     android:orientation="vertical" 
     android:layout_width="240dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start"> 
     <ListView 
      android:id="@+id/listNavFolders" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:listSelector="@android:color/holo_red_light" 
      android:choiceMode="singleChoice" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="0dp" 
      android:background="#111" /> 
    </LinearLayout> 
</android.support.v4.widget.DrawerLayout> 

我設定的選擇與此代碼。這是C#,因爲我使用Xamarin,但我認爲這不應該有所作爲。

this.drawerList.SetSelection(pos); 
this.drawerList.SetItemChecked(pos, true); 

的調用CheckedItemCountCheckedItemPosition都表明值已經設置。我相當確定我已經正確設置了ListView,因爲在屏幕上還有另一個ListView沒有任何問題。

有沒有人有什麼我失蹤的建議?

回答

0

您遺漏了您的drawerList中的項目必須實現SetItemChecked(pos,true)的ICheckable接口才能工作。

如果您使用Xamarin + MvvmCross,我建議您使用this aproach

對於android風格的DrawerLayout,只適用於csharp的this answer