Android: getView() called twice in custom adapter

前端 未结 4 1569
渐次进展
渐次进展 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:20

    I used this. The getView runs twice, but if you check if convertView is null, the code inside will be run once.

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

提交回复
热议问题