GithubHelp home page GithubHelp logo

Comments (6)

thest1 avatar thest1 commented on August 29, 2024

Probably you just do something wrong. I always use viewholder - it should not be a problem. Probably you can show us your code?

from lazylist.

letz avatar letz commented on August 29, 2024
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.live_feed_row, parent, false);

            holder.title = (TextView) convertView.findViewById(R.id.live_feed_title);
            holder.timeAgo = (TextView) convertView.findViewById(R.id.live_feed_time_ago);
            holder.avatar = (AvatarView) convertView.findViewById(R.id.live_feed_avatar);
            convertView.setTag(holder);
        }else
            holder = (ViewHolder) convertView.getTag();

        final NewsActivity activity = getItem(position);
        final String activityType = activity.getActivityType();
        holder.title.setText(Html.fromHtml(activity.getFormattedTitle()));
        holder.timeAgo.setText(Utils.timeAgo(context, activity.getActiveOn()));

        // Display image
        if (activity.hasRelatedUser() && activity.getRelatedUser().getId() > 0) {
            User user = activity.getRelatedUser();
            imageLoader.displayImage(user.getAvatarUrl(), holder.avatar);
        } else {
            holder.avatar.setImageDrawable(context.getResources().getDrawable(R.drawable.mobitto_avatar));
        }

        return convertView;

I make an instance of imageloader on the adapter construtor

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

You can't just call holder.avatar.setImageDrawable because there may be a thread downloading image right now into the same ImageView.

It could be something like that:

// Display image
if (...) {
    ...
    imageLoader.displayImage(...);
} else {
    imageLoader.reset(holder.avatar);
    holder.avatar.setImageDrawable(...);
}

And reset method inside ImageLoader would be:

public void reset(ImageView imageView){
   imageViews.put(imageView, ""); 
}

from lazylist.

letz avatar letz commented on August 29, 2024

still doesn't work.

if (...) {
...
imageLoader.display(...); // this downloads from web a image
} else {
 imageLoader.reset(holder.avatar); // <--- didn't solve
holder.avatar.setImageDrawable(...); // this get's a default image in app resources
}

from lazylist.

thest1 avatar thest1 commented on August 29, 2024

You can also change stub_id in ImageLoader. If you want default image you call display() with empty url. And ImageLoader should should display stub but don't start the download if url if empty.

from lazylist.

letz avatar letz commented on August 29, 2024

i think it worked! thanks!

from lazylist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.