java - drag and drop (checkmark if I drag the right image) android -


if drag countrytypical image , drop in imagecountry[n9] application set checkmark image on right countrytypical image. happens if drag right countrytypical image , if drag mistaken countrytypical image. correct error. many thanks...

string[] countrynames = {         "italy", "france", "spain", "germany", "belgium", "portugal", "switzerland", "great britain" };  int[] countryimages = {         r.drawable.italy,         r.drawable.france,         r.drawable.spain,... }; int[] countryflags = {         r.drawable.italian_flag,         r.drawable.french_flag,         r.drawable.spanish_flag,.... }; 

in oncreate:

countrytypical1.setimageresource(countryflags[n1]);     countrytypical2.setimageresource(countryflags[n2]);     countrytypical3.setimageresource(countryflags[n3]);     countrytypical4.setimageresource(countryflags[n4]);     countrytypical5.setimageresource(countryflags[n5]);     countrytypical6.setimageresource(countryflags[n6]);     countrytypical7.setimageresource(countryflags[n7]);     countrytypical8.setimageresource(countryflags[n8]);      countrytypical1.setontouchlistener(dragclick);     countrytypical2.setontouchlistener(dragclick);     countrytypical3.setontouchlistener(dragclick);     countrytypical4.setontouchlistener(dragclick);     countrytypical5.setontouchlistener(dragclick);     countrytypical6.setontouchlistener(dragclick);     countrytypical7.setontouchlistener(dragclick);     countrytypical8.setontouchlistener(dragclick);      imagecountry.setondraglistener(droplistener); 

view.ontouchlistener dragclick = new view.ontouchlistener() {

    public boolean ontouch(view view, motionevent event) {         if (event.getaction() == motionevent.action_move) {             dragshadow dragshadow = new dragshadow(view);              clipdata dragdata = clipdata.newplaintext("", "");             view.startdrag(dragdata, dragshadow, view,0);             return true;         }         return true;     } };    private class dragshadow extends view.dragshadowbuilder{      public dragshadow(view view) {         super(view);     }     @override     public void onprovideshadowmetrics(point shadowsize, point shadowtouchpoint) {         view view = getview();         int height = view.getheight();         int width = view.getwidth();          shadowsize.set(width, height);         shadowtouchpoint.set(width, height);     }      @override     public void ondrawshadow(canvas canvas) {         getview().draw(canvas);     } }   view.ondraglistener droplistener = new view.ondraglistener() {      @override     public boolean ondrag(view view, dragevent event) {         assigndroptrue(countrytypical1, event, n1);         assigndroptrue(countrytypical2, event, n2);         assigndroptrue(countrytypical3, event, n3);         assigndroptrue(countrytypical4, event, n4);         assigndroptrue(countrytypical5, event, n5);         assigndroptrue(countrytypical6, event, n6);         assigndroptrue(countrytypical7, event, n7);         assigndroptrue(countrytypical8, event, n8);         return true;     }  };    private void assigndroptrue(imageview countrytypical, dragevent event, int n1){     if (n9 == n1){         int dragevent = event.getaction();         switch (dragevent) {             case dragevent.action_drop:                 countrytypical.setimageresource(r.drawable.vcheckmark);         }} } 

i wrote sample give idea behind logic propose (a.k.a it's not tested)

view.ondraglistener droplistener = new view.ondraglistener() {       @override       public boolean ondrag(view view, dragevent event) {           int action = event.getaction();           view draggedview = (view) event.getlocalstate();           //view country flag dropped, draggedview flag dropped           //below check if correct flag dropped in correct country        switch (event.getaction()){         case dragevent.action_drop:            (int i; i< countryimages.length(); i++){                if (draggedview.getid() == countryflags[i] && view.getid()== countryimages[i])                    draggedview.setimageresource(r.drawable.vcheckmark);             }                       break;         default:           break;         }         return true;       }        }; 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -