java - how to make a sorting letter as alphabets -


am new android ,i juz wanna know how make when click button1, button2 text view show 1 2,,, if clicked button2 button1 show 2 1

this codes when click button1 button2, or if clicked button2 button1 shows same,, plz me thanx.

now did using gettext & settext working wanted condition if correct or not not working plz !! wrong , method correct?

protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setrequestedorientation (activityinfo.screen_orientation_portrait);     // full screen     requestwindowfeature(window.feature_no_title);         getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,                               windowmanager.layoutparams.flag_fullscreen);      setcontentview(r.layout.wordgame2);      bu1 = (button) findviewbyid(r.id.bu1);     bu2 = (button) findviewbyid(r.id.bu2);     bu3 = (button) findviewbyid(r.id.bu3);     bu4 = (button) findviewbyid(r.id.bu4);     bu5 = (button) findviewbyid(r.id.bu5);       t1 = (textview) findviewbyid(r.id.t1);      i1 = (imageview) findviewbyid(r.id.i1);     i2 = (imageview) findviewbyid(r.id.i2);      bu1.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             // todo auto-generated method stub              t1.settext(t1.gettext()+" "+bu1.gettext());           }      });      bu2.setonclicklistener(new view.onclicklistener() {                  public void onclick(view v) {                     // todo auto-generated method stub                      t1.settext(t1.gettext()+" "+bu2.gettext());                    }              });      bu3.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             // todo auto-generated method stub              t1.settext(t1.gettext()+" "+bu3.gettext());           }      });      bu4.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             // todo auto-generated method stub               t1.settext(t1.gettext()+" "+bu4.gettext());          }      });      bu5.setonclicklistener(new view.onclicklistener() {          public void onclick(view v) {             // todo auto-generated method stub          if(t1.gettext().tostring().equals("a b c d")) //this not working             {                  i1.setvisibility(view.visible);                 i2.setvisibility(view.invisible);             }                     else {                 i2.setvisibility(view.visible);                 i1.setvisibility(view.invisible);             }         }      });   } 

04-21 07:00:48.690: e/androidruntime(23874): fatal exception: main 04-21 07:00:48.690: e/androidruntime(23874): java.lang.runtimeexception: unable start activity componentinfo{com.arabicalphabets.reham/com.arabicalphabets.reham.wordgame2}: java.lang.nullpointerexception 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread.performlaunchactivity(activitythread.java:1970) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1995) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread.access$600(activitythread.java:127) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread$h.handlemessage(activitythread.java:1161) 04-21 07:00:48.690: e/androidruntime(23874): @ android.os.handler.dispatchmessage(handler.java:99) 04-21 07:00:48.690: e/androidruntime(23874): @ android.os.looper.loop(looper.java:137) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread.main(activitythread.java:4512) 04-21 07:00:48.690: e/androidruntime(23874): @ java.lang.reflect.method.invokenative(native method) 04-21 07:00:48.690: e/androidruntime(23874): @ java.lang.reflect.method.invoke(method.java:511) 04-21 07:00:48.690: e/androidruntime(23874): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:982) 04-21 07:00:48.690: e/androidruntime(23874): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:749) 04-21 07:00:48.690: e/androidruntime(23874): @ dalvik.system.nativestart.main(native method) 04-21 07:00:48.690: e/androidruntime(23874): caused by: java.lang.nullpointerexception 04-21 07:00:48.690: e/androidruntime(23874): @ com.arabicalphabets.reham.wordgame2.oncreate(wordgame2.java:36) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activity.performcreate(activity.java:4465) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1052) 04-21 07:00:48.690: e/androidruntime(23874): @ android.app.activitythread.performlaunchactivity(activitythread.java:1934) 04-21 07:00:48.690: e/androidruntime(23874): ... 11 more

first instead of declaring each button individually use looping declare them...

button[] buttons;  for(int i=0; i<5; i++) {  //for 5 buttons {  string buttonid = "bu" + (i+1);  int resid = getresources().getidentifier(buttonid, "id", getpackagename());  buttons[i] = ((button) findviewbyid(resid)); } 

-using switch() find clicked button...

-and cases implement onclick() below

public void onclick(view v) {         t1.settext(t1.gettext().tostring()+" "+buttons[i].gettext().tostring());  } 

hope works


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -