我想在我的 ListView 中进行图像延迟加载。我将图像放在ViewPager中,然后还为 ViewPager 设置了CirclePageIndicator:
public void fetchDrawableOnThread(final ViewPager viewPager, final CirclePageIndicator indicator) {
final Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
ImagePagerAdapter adapter = new ImagePagerAdapter((Drawable[]) message.obj);
viewPager.setAdapter(adapter);
indicator.setViewPager(viewPager);
}
};
Thread thread = new Thread() {
@Override
public void run() {
Drawable[] drawables = fetchDrawables();
Message message = handler.obtainMessage(1, drawables);
handler.sendMessage(message);
}
};
thread.start();
}
这是我在主 Activity 中的自定义适配器类:
private class MultiAdapter extends ArrayAdapter<String> {
public MultiAdapter(Context context, ArrayList<String> mStrings) {
super(context, R.layout.list_main, mStrings);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (convertView == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.list_main, parent, false);
} else
row = convertView;
ViewPager viewPager = (ViewPager) row.findViewById(R.id.pager);
CirclePageIndicator indicator = (CirclePageIndicator)row.findViewById(R.id.indicator);
if(scroll_is_idle)
drawableMng.fetchDrawableOnThread(viewPager, indicator);
else {
viewPager.setAdapter(null);
}
return row;
}
}
在我的 getView 方法中,我想set viewPager adapter to null, when the scroll is not in idle mode
在 PageIndicator 库 (nullPointerException) 中出现问题。您知道如何重置 PageIndicator 以避免此问题吗?