Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Android GridView highlighting completely (disable selection)

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?

like image 376
Kenny Avatar asked Jul 01 '10 16:07

Kenny


2 Answers

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.

like image 65
Kenny Avatar answered Oct 12 '22 13:10

Kenny


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

like image 32
Maikel Bollemeijer Avatar answered Oct 12 '22 12:10

Maikel Bollemeijer