GridView get view by position, first child view different

前端 未结 3 696
失恋的感觉
失恋的感觉 2020-12-19 05:51

Android GridView is quite interesting, it reuses the child views. The ones scrolled up comes back from bottom. So there is no method from GridView

3条回答
  •  庸人自扰
    2020-12-19 06:36

    After reading source of getPositionForView, I have wrote this method in own GridView, works perfect by API 18

    public View GetViewByPosition(int position) {
        int firstPosition = this.getFirstVisiblePosition();
        int lastPosition = this.getLastVisiblePosition();
    
        if ((position < firstPosition) || (position > lastPosition))
            return null;
    
        return this.getChildAt(position - firstPosition);
    }
    

提交回复
热议问题