【问题标题】:How can I ListView longClick selector?如何 ListView longClick 选择器?
【发布时间】:2013-01-10 06:06:02
【问题描述】:

我想在 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>

【问题讨论】:

    标签: android android-listview android-selector


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 它没有运行。我在我的 onCreate 方法中设置了这段代码。但不运行。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      相关资源
      最近更新 更多