GridView:按位置获取视图

gru*_*unk 9 android gridview

我正在使用网格视图来显示月历.当我触摸日历上的日期时,通过更改其背景和文本颜色来突出显示相应的单元格.一切都像魅力一样,除了我选择一个新约会时我不能不突出显示一个单元格的事实.

当我点击日期时我会记住这个位置,所以当我选择一个新的时候,我知道我之前点击的位置:

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);
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

是否有解决方案来获得他的立场?选择一个单元格并取消选择其他单元格的最有效方法是什么?注意:通过"选择一个单元格",我的意思是通过改变它的样式来突出显示它.

xev*_*ent 18

ViewGroup.getChildAt返回组中指定位置的视图.

GridView.setSelection选择该位置的视图并取消选择其他视图.