W
W
wrewolf2015-05-25 16:57:07
Java
wrewolf, 2015-05-25 16:57:07

Why mush from rows in ListView while updating items in the list?

With a quick scroll down, a pandemonium begins, up to the point that all the elements in the list first begin to travel over each other in 2-3 layers, and then if you continue to scroll, they disappear altogether and the scrollbar disappears until all the elements are reloaded, as if it were not can calculate the element's height, although it cannot be less than some constant.
When using such code, the viewHolder is not affected, as it was before its introduction.

if (convertView == null) {
  convertView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_row, null);
  viewHolder = new ViewHolder();
  viewHolder.status = (TextView) convertView.findViewById(R.id.status);
  viewHolder.dinamic_content = (LinearLayout) convertView.findViewById(R.id.dinamic_content);
  convertView.setTag(viewHolder);
} else {
    viewHolder = (ViewHolder) convertView.getTag();
    viewHolder.dinamic_content.removeAllViews();
}

if always do
convertView = ((LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_row, null);

then there is no such problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Emin, 2015-05-25
@wrewolf

For starters, it's better to store the Inflater once in the adapter's constructor

private LayoutInflater mInflater;
...
mInflater = LayoutInflater.from(context);

Then try this design, redoing it for yourself
@Override public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.sort_spinner_item, parent, false);
            holder = new ViewHolder(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(getTitle(position));       

        return convertView;
    }

public static class ViewHolder {
        @InjectView(android.R.id.text1) TextView textView;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
            view.setTag(this);
        }
    }

The problem seems to be what you are using.
instead of
convertView = mInflator.inflate(R.layout.custom_row, parent, false );

W
wrewolf, 2015-05-25
@wrewolf

Not long rejoiced at the smooth scrolling as the mixing began again. But, in this way, it generally began to swallow the elements, and in the body of the list it twists the elements several times.
Although this is to blame for caching.
After creating the view, I do this.
views.put(item.getId(), new WeakReference<>(convertView));
With caching disabled, it works 100% correctly, but there is a twitch due to reloading the contents of the card. We need to try to put the content in the cache and render without loading it from the source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question