Why is Android recycling the wrong view type in my SpinnerAdapter?

后端 未结 2 2286
耶瑟儿~
耶瑟儿~ 2021-02-15 19:46

I\'m trying to make an ActionBar spinner that has separators. I have implemented a SpinnerAdapter that has 2 item view types (thanks to getViewTypeCount

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 19:57

    The problem is here:

    public View getView(final int position, final View convertView, final ViewGroup parent) {
        return getView(mActionBarItemLayoutResId, position, convertView, parent);
    }
    

    This method will always return the same View type, whether called for a separator or a data item. You need to check the position here and return an appropriate view.

提交回复
热议问题