2011-05-25 211 views
0

當我嘗試單擊列表視圖項目時,不顯示選擇器。這是我的ListView創建自定義列表視圖選擇器的問題

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/streamRelativeLayout"> 
    <ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/streamListView" android:cacheColorHint="#00000000" android:fadingEdge="none" android:listSelector="@drawable/swipeview_list_selector"> </ListView> 
    <TextView android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="@+id/noStreamTextView" android:layout_width="wrap_content" android:text="No Stream Available" android:visibility="invisible"></TextView> 
    <ProgressBar android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="@+id/streamProgressBar" android:layout_width="wrap_content"></ProgressBar> 
</RelativeLayout> 

這是我的選擇:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_enabled="false" android:state_focused="true" 
     android:drawable="@drawable/stocks_gradient" /> 
    <item android:state_pressed="true" 
     android:drawable="@drawable/stocks_gradient" /> 
    <item android:state_focused="true" 
     android:drawable="@drawable/stocks_gradient" /> 
</selector> 

這裏是梯度:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#ECECEC" 
     android:centerColor="#F6F6F4" 
     android:endColor="#F8F8F6" 
     android:angle="90" 
     android:dither="true" 
    /> 
</shape> 

我也設置背景顏色交替在getView()

int colorPos = position % colors.length; 
      v.setBackgroundColor(colors[colorPos]); 

回答

0

我需要將selectorontop屬性設置爲true。

0

如果你的意思是選擇的項目沒有顯示你所希望的方式,那是因爲你錯過了state_selected情況:

<item android:state_selected="true" android:drawable="..."/> 
+0

我補充說,仍然沒有出現。 – 2011-05-25 15:47:10

0

第一個問題,我看到的是,所有的國家都使用同樣的drawable,所以當你點擊它時你不會看到變化。而且你沒有考慮過所有的情況,例如你沒有默認狀態。