0

I'm making a Pulse kind of UI for my app. For this I'm using HorizontalListView class as given here. However, this class has performance issues and delivers a noticeable lag.

To confirm this I assessed it using TraceView Profiler and found that this class doesn't reuse views altogether and calls inflate() method for every call inside getView().

Here is how I'm designing the adapter:

public View getView(final int position, View convertView, ViewGroup parent) {
    final BaseAssets baseAsset = baseAssetsList.get(position);

    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = inflater.inflate(R.layout.gallery_list_item, parent, false);
        viewHolder.newLabel = (ImageView) convertView.findViewById(R.id.iv_new);
        viewHolder.assetImage = (ImageView) convertView.findViewById(R.id.iv_thumbnail);
        convertView.setTag(viewHolder);

    } else
        viewHolder = (ViewHolder) convertView.getTag();
 }

class ViewHolder {
    ImageView newLabel;
    ImageView assetImage;
 }

Am I doing anything wrong? If not, please suggest me workarounds to improve performance. Possibly some other library you would have tried or any way to reuse views in my current library. Thanks !

Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44

1 Answers1

1

Seems like you're never calling convertView.setTag(viewHolder); in the case the convertView is null. You cant retrieve the ViewHolder without first setting it as the tag.

EDIT:

Other than that your code seems fine, my best guess would be that the problem lies in the implementation of the HorizontalListView.

I looked at its source (HorizontalListView.java) and if you can experiment with the source, try checking if mRemovedViewQueue is empty before it makes any calls to mAdapter.getView.If it is, then its not handling the recycling properly.

Akash
  • 631
  • 1
  • 8
  • 16