Disable Android GridView highlighting completely (disable selection)

前端 未结 4 2009
既然无缘
既然无缘 2020-12-31 10:01

I\'m trying to disable the highlighting of objects in a GridView in Android 2.2.

I found this other answer saying that I should set the selector to a transparent Col

相关标签:
4条回答
  • 2020-12-31 10:33

    Just Set v.setOnClickListener(null);

    0 讨论(0)
  • 2020-12-31 10:35

    In the definition of your Adapter for the GridView, you will have to override the following methods:

    @Override
    public boolean areAllItemsEnabled()
    {
        return false;
    }
    
    @Override
    public boolean isEnabled(int position)
    {
        return false;
    }
    

    This will cause all of the items in your grid to be non-selectable, and will get rid of the highlight completely.

    0 讨论(0)
  • 2020-12-31 10:35

    For keeping the items clickable you should use below attr. in your GridView xml:

    android:listSelector="#00000000"

    See also: https://stackoverflow.com/a/2866074/928591

    0 讨论(0)
  • 2020-12-31 10:55

    If you just want to disable the visual aspect of the selection, you can do the following:

    gridview.getSelector().setAlpha(0);
    
    0 讨论(0)
提交回复
热议问题