Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView : Get a view by position

I'm using a grid view to display a month calendar. When i touch a date on the calendar , the corresponding cell is highlighted by changing its background and text Color. Everything works like charm except the fact that i can't un-highlight a cell if i choose a new date.

When i click a date i remember the position, so when i chose a new one i know where i clicked previously :

protected OnClickListener onClicThisMonthDate(final int position)
{
    return new OnClickListener() {

        @Override
        public void onClick(View v) 
        {
            if(prevDateSelected > -1 )
            {
                //Get the view by the oldPosition
                //Change its background and text color
            }
            prevDateSelected = position;
            TextView casecal = (TextView) v.findViewById(R.id.case_cal);
            casecal.setBackgroundColor(Color.rgb(93, 94, 94));
            casecal.setTextColor(Color.WHITE);
        }
    };
}

Is there a solution to get a view by his position ? What's the most efficient way to select a cell and unselect all the other ? Note : By "select a cell" i mean highlight it, by changing it style.

like image 793
grunk Avatar asked Jul 05 '11 13:07

grunk


1 Answers

ViewGroup.getChildAt returns the view at the specified position in the group.

GridView.setSelection selects of the view at the position and unselects others views.

like image 173
xevincent Avatar answered Oct 03 '22 16:10

xevincent