我如何ListView长按选择器?

时间:2013-01-26 10:22:59

标签: android android-listview android-selector

我想在longclick上更改自定义列表视图的背景颜色。这是我的选择器,但只运行onClick。我该怎么办?

*的 tables_row_selector.xml *

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_selected="true" 
        android:drawable="#8D2EE4" />

    <item android:state_activated="true" 
        android:drawable="@color/ThemeBlue" />

    <item android:state_activated="true" android:state_focused="false"
        android:drawable="@color/ThemeBlue" />   

    <item android:state_pressed="true" >
        <shape>
            <gradient
                android:startColor="#0266e9"
                android:endColor="#0484f2"
                android:angle="90" />

        </shape>
    </item>

    <item android:state_focused="true" >
        <shape>
            <gradient
                android:startColor="#bbccff"
                android:endColor="#dce4fd"
                android:angle="90" />                                
        </shape>
    </item>

    <item>        
        <shape>
            <solid android:color="#00000000"></solid>
        </shape>
    </item>
</selector>

2 个答案:

答案 0 :(得分:0)

将LongClickListener(http://developer.android.com/reference/android/view/View.OnLongClickListener.html)添加到表格行。

答案 1 :(得分:0)

试试这个:

YourList.setOnItemLongClickListener(new OnItemLongClickListener(){ 
    @Override   
    public boolean onItemLongClick(AdapterView parentView, View childView, int position, long id) {
    return true;}});