Android Adapter multiple getView

前端 未结 4 891
一生所求
一生所求 2021-02-15 15:45

i have read about the issue of getView called multiple times and all the answers. However, i don\'t find a solution for my problem.

I have a list where rows have two sta

4条回答
  •  轮回少年
    2021-02-15 16:31

    Here is a very simple way of avoiding the double call when you know nothing below this block of code will distort the layout.

    private static List usedPositions  = new ArrayList();
    

    ...

    @Override
    public View getView(int position, View rowView, ViewGroup parent) {
        rowView = inflater.inflate(R.layout.download_listview_item, null);
    
        Log.d(LOG_TAG, "--> Position: " + position);
    
        if (!usedPositions.contains(String.valueOf(position))){
            usedPositions.add(String.valueOf(position));
            return rowView;
        }else{
            usedPositions.remove(String.valueOf(position));
        }
    

    ...

提交回复
热议问题