12

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 ColorDrawable (android:listSelector="@android:color/transparent"), but the views in my GridView are still dimmed when I select them.

I'm just using the GridView to display static objects in a grid. None of these objects will be selected. Would it be better to just use a basic view and draw my images manually?

Community
  • 1
  • 1
Kenny
  • 123
  • 1
  • 1
  • 4
  • check this out https://stackoverflow.com/questions/18415844/disable-gridview-item-onclick-and-enable-only-on-child-view – sushmita Feb 05 '15 at 05:26

4 Answers4

39

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

Community
  • 1
  • 1
Maikel Bollemeijer
  • 6,545
  • 5
  • 25
  • 48
24

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.

blahdiblah
  • 33,069
  • 21
  • 98
  • 152
Kenny
  • 356
  • 1
  • 3
  • 7
1

Just Set v.setOnClickListener(null);

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
jfleong
  • 96
  • 3
0

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

gridview.getSelector().setAlpha(0);
Larpus
  • 301
  • 1
  • 3
  • 17