开发者

Problem creating a custom ListView selector

When I try clicking on a a listview item no selector is shown. Here is my 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"></Pro开发者_如何学CgressBar>
</RelativeLayout>

Here is my selector:

<?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>

Here is the gradient:

<?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>

I am also setting the background color to alternate in getView()

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


If you mean that selected item is not displayed the way you want, then that's because you missed the state_selected case:

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


The first issue I see is that all of your states use the same drawable, so you wouldn't see a change when you click on it. And you haven't accounted for all of the cases, for example you have no default state.


i need to set the selectorontop property to true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜