1

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

*表行选择器.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>
4

2 回答 2

0

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

于 2013-01-26T10:29:34.147 回答
0

尝试这个 :

YourList.setOnItemLongClickListener(new OnItemLongClickListener(){ 
    @Override   
    public boolean onItemLongClick(AdapterView parentView, View childView, int position, long id) {
    return true;}});
于 2013-01-26T10:40:06.170 回答