GridView : Get a view by position

Viewed 15815

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.

1 Answers
Related