android - Viewpager position 0 doesnt work with onPageSelected(0) -
i cant set value start page (position 0)
i mean questionpageradapter.tv.settext("default") must work in mainactivity's onpageselected(int position) case 0: gives nullpoint. works position > 0
pageradapter:
public class questionpageradapter extends pageradapter{ public static textview tv; @override public object instantiateitem(view collection, int pos) { layoutinflater inflater = (layoutinflater) collection.getcontext() .getsystemservice(context.layout_inflater_service); view page = inflater.inflate(r.layout.page_quiz, null); tv = (textview)page.findviewbyid(r.id.questiontext); } }
mainactivity:
@override protected void oncreate(final bundle savedinstancestate) { super.oncreate(savedinstancestate); this.setcontentview(r.layout.activity_main); mpager = (viewpager)findviewbyid(r.id.pager); questionpageradapter madapter = new questionpageradapter(); mpager.setadapter(madapter); @override public void onpageselected(int position) { switch (position) { case 0: // questionpageradapter.tv.settext("default"); => doesnt works break; default: questionpageradapter.tv.settext("default"); => works break; }
since have textview instance passed asynctask, can use onpreexecute() method set default value before task starts executing. onpreexecute() method runs on ui thread shouldn't issue.
http://developer.android.com/reference/android/os/asynctask.html#onpreexecute()
Comments
Post a Comment