Android ListView滞后于ImageLoader

时间:2012-11-20 01:47:51

标签: android android-listview lazy-loading

我正在使用androidimageloader.com并且当图像加载到列表中时会获得一些闪烁,这与使用它的演示和应用程序非常不同。我在应用程序类中有imageLoader,并且不明白为什么它会闪烁。这些图片是用户的Facebook个人资料图片。会导致什么?这是我的适配器:

public class FriendAdapter extends BaseAdapter {
    private Typeface tf;
    LayoutInflater inflater;
    private String[] nameEvents;
    private String[] urls;
    private ArrayList<Friend> friends;
    ImageManager imageManager;
    ImageTagFactory imageTagFactory;

    public FriendAdapter(Activity activity, ArrayList<Friend> friends) {
        this.friends = friends;
        setData(this.friends);
        tf = Typeface.createFromAsset(activity.getAssets(),
                "fonts/Roboto-Condensed.ttf");
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageManager = BuzzbabaApplication.getImageLoader();
        imageTagFactory = new ImageTagFactory(activity, R.drawable.no_pic_icon);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        FriendView fView;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.friend_layout, null);
            fView = new FriendView();
            fView.name = (TextView) convertView.findViewById(R.id.friendName);
            fView.name.setTypeface(tf);
            fView.pic = (ImageView) convertView.findViewById(R.id.profilePic);
            convertView.setTag(fView);
        } else {
            fView = (FriendView) convertView.getTag();
        }
        fView.name.setText(nameEvents[position]);
        // HomeScreen.imageLoader.DisplayImage(urls[position], fView.pic);
        ((ImageView) fView.pic).setTag(imageTagFactory.build(urls[position]));
        imageManager.getLoader().load(fView.pic);
        return convertView;
    }

    public void setData(ArrayList<Friend> friends) {
        nameEvents = new String[friends.size()];
        urls = new String[friends.size()];
        int index = 0;
        for (Friend f : friends) {
            String pos = f.getName();
            int num = f.getNumEvents();
            if (num == 1) {
                pos = pos + "\n" + num + " event";
            } else {
                pos = pos + "\n" + num + " events";
            }
            nameEvents[index] = pos;
            urls[index] = f.getPictureURL();
            index++;
        }
    }

    static class FriendView {
        TextView name;
        ImageView pic;
    }

    public int getCount() {
        return friends.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

}

0 个答案:

没有答案