How to change images after it compare on button next in android? -



How to change images after it compare on button next in android? -

i have next , previous button. want alter images after comparing images comes previous activity using next button click. got image value using bundle object. there 26 alphabets images alter on next button event on previous button event. below source code performing alter images on button event(next, previous).

private drawingview mdrawingview; bundle extras = getintent().getextras(); int imageres1 = extras.getint("picture1"); int imageres2 = extras.getint("picture2"); mdrawingview = (drawingview) findviewbyid(r.id.drawing_view); mdrawingview.setshape(imageres1, imageres2); btn_next = (button) findviewbyid(r.id.btn_next); // btn_next.setonclicklistener(this); btn_next.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub initializemp(); playsound.start(); if(imageres1==r.drawable.img_a_inner||imageres2==r.drawable.img_a){ mdrawingview.setshape(r.drawable.img_b_inner, r.drawable.img_b); index++; } else if(imageres1==r.drawable.img_b_inner||imageres2==r.drawable.img_b){ mdrawingview.setshape(r.drawable.img_c_inner, r.drawable.img_c); index++; } else if(imageres1==r.drawable.img_c_inner||imageres2==r.drawable.img_c){ mdrawingview.setshape(r.drawable.img_d_inner, r.drawable.img_d); index++; } else if(imageres1==r.drawable.img_d_inner||imageres2==r.drawable.img_d){ mdrawingview.setshape(r.drawable.img_e_inner, r.drawable.img_e); index++; } } }); btn_prev = (button) findviewbyid(r.id.btn_prev); // btn_prev.setonclicklistener(this); btn_prev.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub initializemp(); playsound.start(); if(imageres1==r.drawable.img_b_inner||imageres2==r.drawable.img_b){ mdrawingview.setshape(r.drawable.img_a_inner, r.drawable.img_a); index--; } else if(imageres1==r.drawable.img_c_inner||imageres2==r.drawable.img_c){ mdrawingview.setshape(r.drawable.img_b_inner, r.drawable.img_b); index--; } else if(imageres1==r.drawable.img_d_inner||imageres2==r.drawable.img_d){ mdrawingview.setshape(r.drawable.img_c_inner, r.drawable.img_c); index--; } }); }

after using code got current position of image , when press next button 1 time image changed. want alter image continously using next , previous button click.

you can declare viewflipper component in xml layout, , add together programatically images imageview viewflipper. can images this:

string mpath = "your images folder"; file file = new file(mpath); file[] files = file.listfiles(); if(files != null) { imageview imageview; bitmap bitmap; for(file infile : files) { bitmap = bitmapfactory.decodefile(infile.getabsolutepath()); imageview = new imageview(this); imageview.setimagebitmap(bitmap); linearlayout layout = new linearlayout(mcontext); layout.settag(infile.getabsolutepath()); layout.addview(imageview); mviewflipper.addview(layout); } }

in point, have imageview set viewflipper. can phone call 'shownext()', 'showprevious()', 'startflipping()', 'stopflipping()' methods. if want utilize buttons should phone call methods in yout buttonclicklistener.

android image button

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -