Android onClick method ImageSwitcher -


basically got 1 array has 2 image if have more. images array switcher every few seconds. i'm stuck onclick method. ultimate goal when user clicks on image new activity class opens up. each image has own activity class when user clicks on it, should directed particular class.

i did got yesterday

public void onclick(view v) {        intent n = null;        int id = v.getid();        switch (id){            case r.id.someid:                 n = new intent(getactivity(), fragment1.class);                 break;            case r.id.someotherid:                 n = new intent(getactivity(), fragment2.class);                 break;         } 

i can set first case statement "r.id.textswitcher" second problem. because want images animates @ 1 place, new r.id... means new location new "mswitcher1.setonclicklistener(new view.onclicklistener()"

public class animation extends fragment implements animationlistener {      public homeanimation(){}     private static boolean flag = false;      animation anim;      private handler handler;      public imageswitcher mswitcher,mswitcher1;      int texttoshow[] = {r.drawable.dabangg, r.drawable.car };      int messagecount = texttoshow.length;     int currentindex = -1;     @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {        view v = inflater.inflate(r.layout.imgswitch, container, false);         mswitcher = (imageswitcher) v.findviewbyid(r.id.imageswitcher1);         mswitcher.setfactory(mfactory);         anim = animationutils.loadanimation(getactivity(),r.anim.fade_in);          mswitcher.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 intent n = null;                  int id = v.getid();                 // fragment fragment = null;                 //bundle args = new bundle();                 switch (v.getid()){                 case 0:                     n = new intent(getactivity(), fragment1.class);                     getactivity().startactivity(n);                     break;                 case 1:                     n = new intent(getactivity(), fragment2.class);                     getactivity().startactivity(n);                     break;                 }             }         });         // set animation listener         anim.setanimationlistener(this);         return v;         }  public void updatetextview() {      int maxindex = texttoshow.length;     random random = new random();     int generatedindex = random.nextint(maxindex);     mswitcher.setimageresource(texttoshow[generatedindex]); 

}

here updated in case if needs it

public void updatetextview() {          int maxindex = texttoshow.length;         random random = new random();         final int generatedindex = random.nextint(maxindex);         mswitcher.setimageresource(texttoshow[generatedindex]);         mswitcher.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 intent n = null;                   switch(generatedindex){                  case 0:                      n = new intent(getactivity(), fragment1.class);                        getactivity().startactivity(n);                        break;                   case 1:                       n = new intent(getactivity(), fragment2.class);                        getactivity().startactivity(n);                        break;                  case 2:                        n = new intent(getactivity(), fragment3.class);                        getactivity().startactivity(n);                        break;                  }             }          }); 

i don't have time test right , i'm not sure understand problem try , see if want. put comments in code

mswitcher.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             intent n = null;              int id = v.getid();             // fragment fragment = null;             //bundle args = new bundle();             switch (v.getid()){             case 0:               /*                   below should give index displayed image                  can compare ids in array using index               */                if (v.getdisplayedchild() == 0) { // if 1st image in array                    n = new intent(getactivity(), fragment1.class);                    getactivity().startactivity(n);                }                if (v.getdisplayedchild() == 1) { // if 2nd image in array                    n = new intent(getactivity(), fragment2.class);                    getactivity().startactivity(n);                }               break; 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -