Android: getView() called twice in custom adapter

前端 未结 4 1570
渐次进展
渐次进展 2021-02-13 04:53

I\'m setting a custom SimpleCursorAdapter to a ListView. For some reason FriendAdapter\'s getView() is called twice for every item in the DB. After some investigation (I have no

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 05:31

    In order to getView get call only once for each row, you need to call super.getView and then change the returned view. It's something like this

    public View getView(int position, View convertView, ViewGroup parent) {
        View superView = super.getView(position, convertView, parent);
        if (mCursor.moveToPosition(position)) {
             // Customize superView here
    
        }
        return superView;
    }
    

提交回复
热议问题