android - Execute Thread in every Viewpager item -
- i have 2 images, in single viewpager item. when clicking on image display line, simple line.
- i growing line using thread, line percentage of vote given particular image, based on percentage lines drawn on both image after click
but problem if click on 1 image single line drawn on particular image, , every other viewpager items no line drawn on click
i want 2 lines after click on image,
ivimageone.setonclicklistener(new view.onclicklistener() { @override public void onclick(final view v) { id = arraylist.get(position).get("user_id1"); feed_id = arraylist.get(position).get("feed_id"); log.e("feeeeeee", feed_id); view tempview = (view) v.gettag(r.integer.btnminusview); integer pos = (integer) v.gettag(r.integer.btnminuspos); ivrighttick = (imageview) tempview.findviewbyid(r.id.ivrighttick); ivlefttick = (imageview) tempview.findviewbyid(r.id.ivlefttick); ivlefttick.setvisibility(view.gone); ivrighttick.setvisibility(view.visible); vone = (view) tempview.findviewbyid(r.id.vone); vtwo = (view) tempview.findviewbyid(r.id.vtwo); mthread = new thread() { @override public void run() { while (pstatus < pcount1) { pstatus += 10; handler.post(new runnable() { @override public void run() { android.view.viewgroup.layoutparams params = vone.getlayoutparams(); params.height = pstatus; params.width = 10; log.d("pppppppppppppp", params.height + ""); vone.setlayoutparams(params); // vone.setlayoutparams(new windowmanager.layoutparams(1,pstatus)); if (pstatus == pcount1) { stopthread(mthread); } } }); try { thread.sleep(19); //thread take approx 2.5 seconds finish } catch (interruptedexception e) { e.printstacktrace(); } } } }; mthread2 = new thread() { @override public void run() { while (pstatus2 > min_value) { pstatus2 += 10; handler2.post(new runnable() { @override public void run() { android.view.viewgroup.layoutparams params = vtwo.getlayoutparams(); params.height = pstatus; params.width = 10; log.d("pppppppppppppp", params.height + ""); vtwo.setlayoutparams(params); // vone.setlayoutparams(new windowmanager.layoutparams(1,pstatus)); if (pstatus2 == pcount2) { stopthread(mthread2); } } }); try { thread.sleep(19); //thread take approx 2.5 seconds finish } catch (interruptedexception e) { e.printstacktrace(); } } } }; mthread.start(); mthread2.start(); } }); ivfeedimagetwo.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // givevote(2); id = arraylist.get(position).get("user_id2"); feed_id = arraylist.get(position).get("feed_id"); view tempview = (view) v.gettag(r.integer.btnminusview); integer pos = (integer) v.gettag(r.integer.btnminuspos); ivlefttick = (imageview) tempview.findviewbyid(r.id.ivlefttick); ivrighttick = (imageview) tempview.findviewbyid(r.id.ivrighttick); ivlefttick.setvisibility(view.visible); ivrighttick.setvisibility(view.gone); vone = (view) tempview.findviewbyid(r.id.vone); vtwo = (view) tempview.findviewbyid(r.id.vtwo); mthread = new thread() { @override public void run() { while (pstatus < pcount2) { pstatus += 10; handler.post(new runnable() { @override public void run() { android.view.viewgroup.layoutparams params = vtwo.getlayoutparams(); params.height = pstatus; params.width = 10; log.d("pppppppppppppp", params.height + ""); vtwo.setlayoutparams(params); // vone.setlayoutparams(new windowmanager.layoutparams(1,pstatus)); if (pstatus == pcount2) { stopthread(mthread); } } }); try { thread.sleep(19); //thread take approx 2.5 seconds finish } catch (interruptedexception e) { e.printstacktrace(); } } } }; mthread2 = new thread() { @override public void run() { while (pstatus2 > min_value) { pstatus2 += 10; handler2.post(new runnable() { @override public void run() { android.view.viewgroup.layoutparams params = vone.getlayoutparams(); params.height = pstatus; params.width = 10; log.d("pppppppppppppp", params.height + ""); vone.setlayoutparams(params); // vone.setlayoutparams(new windowmanager.layoutparams(1,pstatus)); if (pstatus2 == pcount1) { stopthread(mthread2); } } }); try { thread.sleep(19); //thread take approx 2.5 seconds finish } catch (interruptedexception e) { e.printstacktrace(); } } } }; mthread2.start(); mthread.start(); } });
here's how handle immediate problem:
code method on activity/fragment starts animation 2 lines. set 2 identical onclicklistener
s, 1 on each image, call animation method.
what i'm more concerned use of thread
s animation. not android way. should use animator make visual change view. code simple as:
float pct = ... // ratio of votes total votes, 0.0 1.0 vone.setscalex(0f); vone.animate().setduration(150).scalexby(pct).start();
please @ of animation tutorials on android developers site , elsewhere on web.
Comments
Post a Comment