android - After Animation JSON load -
i new in android development.
i developing app in have add intro slides after animation end problem is, have data(image , title) json , show in slides. getting data unable update slides.
i have tried call json class animationend()
getting null object reference.
please me. thankfull.
here code.
mainactivity
public class mainactivity extends appcompatactivity implements animation.animationlistener { imageview img; animation animfadein; stringbuffer finalstring = new stringbuffer(); private textview title1, title2, title3; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); img = (imageview) findviewbyid(r.id.imageview); animfadein = animationutils.loadanimation(getapplicationcontext(), r.anim.fade_in); animfadein.setanimationlistener(this); img.startanimation(animfadein); //img.startanimation(animzoomin); title1 = (textview) findviewbyid(r.id.txt_title1); title2 = (textview) findviewbyid(r.id.txt_title2); title3 = (textview) findviewbyid(r.id.txt_title3); //new jsontask().execute("https://www.prepforsure.com/engine/admin/mobileapi.php?action=addinto_api"); } @override public void onanimationstart(animation animation) { new jsontask().execute("https://www.prepforsure.com/engine/admin/mobileapi.php?action=addinto_api"); } @override public void onanimationend(animation animation) { intent = new intent(this, introactivity.class); startactivity(i); new jsontask().execute("https://www.prepforsure.com/engine/admin/mobileapi.php?action=addinto_api"); } @override public void onanimationrepeat(animation animation) { } public class jsontask extends asynctask<string, string, string> { @override protected string doinbackground(string... params) { httpurlconnection connection = null; bufferedreader reader = null; try { url url = new url(params[0]); connection = (httpurlconnection) url.openconnection(); connection.connect(); inputstream inputstream = connection.getinputstream(); reader = new bufferedreader(new inputstreamreader(inputstream)); string line = ""; stringbuffer buffer = new stringbuffer(); while ((line = reader.readline()) != null) { buffer.append(line); } string finaljson = buffer.tostring(); //get json array jsonarray parentarray = new jsonarray(finaljson); (int = 0; < parentarray.length(); i++) { jsonobject firstobject = parentarray.getjsonobject(i); string title = firstobject.getstring("title"); finalstring.append(title + "\n"); } //return buffer.tostring(); return finalstring.tostring(); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } catch (jsonexception e) { e.printstacktrace(); } { if (connection != null) { connection.disconnect(); } try { if (reader != null) { reader.close(); } } catch (ioexception e) { e.printstacktrace(); } } return null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); //toast.maketext(getapplicationcontext(), result, toast.length_long).show(); title1 = (textview) findviewbyid(r.id.txt_title1); title1.settext(result); } } }
introactivity
public class introactivity extends appcompatactivity { private viewpager viewpager; private viewpageradapter viewpageradapter; private linearlayout dotslayout; private textview[] dots; private int[] layouts; private button btnskip, btnnext; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_intro); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); viewpager = (viewpager) findviewbyid(r.id.intro_view_pager); dotslayout = (linearlayout) findviewbyid(r.id.layoutdots); btnskip = (button) findviewbyid(r.id.btn_skip); btnnext = (button) findviewbyid(r.id.btn_next); layouts = new int[]{ r.layout.slide1, r.layout.slide2, r.layout.slide3}; // adding bottom dots addbottomdots(0); viewpageradapter = new viewpageradapter(); viewpager.setadapter(viewpageradapter); viewpager.addonpagechangelistener(viewpagerpagechangelistener); } @override protected void onstart() { super.onstart(); } public void btnskipclick(view v) { launchhomescreen(); } public void btnnextclick(view v) { // checking last page // if last page home screen launched int current = getitem(1); if (current < layouts.length) { // move next screen viewpager.setcurrentitem(current); } else { launchhomescreen(); } } viewpager.onpagechangelistener viewpagerpagechangelistener = new viewpager.onpagechangelistener() { @override public void onpageselected(int position) { addbottomdots(position); // changing next button text 'next' / 'got it' if (position == layouts.length - 1) { // last page. make button text got btnnext.settext(getstring(r.string.start)); btnskip.setvisibility(view.gone); } else { // still pages left btnnext.settext(getstring(r.string.next)); btnskip.setvisibility(view.visible); } } @override public void onpagescrolled(int arg0, float arg1, int arg2) { } @override public void onpagescrollstatechanged(int arg0) { } }; private void addbottomdots(int currentpage) { dots = new textview[layouts.length]; dotslayout.removeallviews(); (int = 0; < dots.length; i++) { dots[i] = new textview(this); dots[i].settext(html.fromhtml("•")); dots[i].settextsize(35); dots[i].settextcolor(getresources().getcolor(r.color.dot_inactive)); dotslayout.addview(dots[i]); } if (dots.length > 0) dots[currentpage].settextcolor(getresources().getcolor(r.color.dot_active)); } private int getitem(int i) { return viewpager.getcurrentitem() + i; } private void launchhomescreen() { startactivity(new intent(this, welcome_activity.class)); finish(); } public class viewpageradapter extends pageradapter { private layoutinflater layoutinflater; public viewpageradapter() { } @override public object instantiateitem(viewgroup container, int position) { layoutinflater = (layoutinflater) getsystemservice(context.layout_inflater_service); view view = layoutinflater.inflate(layouts[position], container, false); container.addview(view); return view; } @override public int getcount() { return layouts.length; } @override public boolean isviewfromobject(view view, object obj) { return view == obj; } @override public void destroyitem(viewgroup container, int position, object object) { view view = (view) object; container.removeview(view); } } }
Comments
Post a Comment