android - Reset CirclePageIndicator library -
i wanted have image lazy loading in listview. put images in viewpager, , set circlepageindicator viewpager:
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(); }
this custom adapter class in main 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; } }
in getview method, want set viewpager adapter null, when scroll not in idle mode
, makes problem in pageindicator library (nullpointerexception). know how can reset pageindicator avoid problem?
i know logic may not good:
if(scroll_is_idle) drawablemng.fetchdrawableonthread(viewpager, indicator); else viewpager.setadapter(null);
but way made problem in ondraw method in viewpageindicator library, nullponiterexception.
i solved problem editing ondraw , add mviewpager.getadapter() == null
condition:
@override protected void ondraw(canvas canvas) { super.ondraw(canvas); if (mviewpager == null || mviewpager.getadapter() == null) { return; }
Comments
Post a Comment