How to load the Listview “smoothly” in android

I will describe you how to get such issue that you have. Possibly this will help you.

So, in list adapter you have such code:

public View getView(int position, View contentView, ViewGroup arg2)
    {
        ViewHolder holder;

        if (contentView == null) {
            holder = new ViewHolder();
            contentView = inflater.inflate(R.layout.my_magic_list,null);
            holder.label = (TextView) contentView.findViewById(R.id.label);
            contentView.setTag(holder);
        } else {
            holder = (ViewHolder) contentView.getTag();
        }

        holder.label.setText(getLabel());

        return contentView;
    }

As you can see, we set list item value only after we have retrieved holder.

But if you move code into above if statement:

holder.label.setText(getLabel());

so it will look after like below:

if (contentView == null) {
   holder = new ViewHolder();
   contentView = inflater.inflate(R.layout.my_magic_list,null);
   holder.label = (TextView) contentView.findViewById(R.id.label);
   holder.label.setText(getLabel());
   contentView.setTag(holder);
}

you will have your current application behavior with list item duplication.

Possibly it will help.

Leave a Comment