Skip to content Skip to sidebar Skip to footer

Set Highlighted Item In Gridview On Android

Sometimes I am really amazed to see that simple things have hard to find solutions. I have a GridView with 6 columns and multiple rows. Each item is a square having a color as back

Solution 1:

The simplest way is to save the position and check it inside your Adapter class inside getView() method.

if(selected_position = position){
    view.setBackgroundResource(selected_resource_id);
}
else{
    view.setBackgroundResource(resource_id);
}

And then just call notifyDataSetChanged() on your Adapter.

Post a Comment for "Set Highlighted Item In Gridview On Android"