java - OnClickListener not functioning as expected -


i have onclicklistener @ line:

massistupdatebutton = (button) findviewbyid(r.id.assist_instr_btn);         massistupdatebutton.setonclicklistener(this); 

which supposed call:

public void onclick(view v) {     if (v == massistupdatebutton) { 

but not seem reach point in code. i've looked on several times , cannot seem figure out i've done wrong.

any input appreciated.

source:

import java.io.ioexception; import java.io.inputstream; import java.util.arraylist; import javax.xml.parsers.parserconfigurationexception;  import org.xml.sax.saxexception;  import android.annotation.suppresslint; import android.annotation.targetapi; import android.app.activity; import android.app.alertdialog; import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.contentresolver; import android.content.contentvalues; import android.content.context; import android.content.dialoginterface; import android.content.intent; import android.database.cursor; import android.database.sqlexception; import android.net.uri; import android.os.build; import android.os.build.version_codes; import android.os.bundle; import android.provider.settings; import android.telephony.telephonymanager; import android.text.html; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview;  public class configfinalactivity extends activity implements onclicklistener {     private static final string tag = "configactivity";     telephonymanager tm;     alertdialog merroralert = null;     private notification mnotification = null;     private button mxbutton = null;     private button massistupdatebutton = null;     private button massistinstrbutton = null;     private button mreadagainbutton = null;     private int minstructionnumber = 0;     public static arraylist<string> namearr = new arraylist<string>();     public static arraylist<string> valuearr = new arraylist<string>();     public static arraylist<string> namearr = new arraylist<string>();     public static arraylist<string> apnarr = new arraylist<string>();     public static arraylist<string> mmscarr = new arraylist<string>();     public static arraylist<string> mmsportarr = new arraylist<string>();     public static arraylist<string> mmsproxyarr = new arraylist<string>();     public static arraylist<string> portarr = new arraylist<string>();     public static arraylist<string> proxyarr = new arraylist<string>();     public static int count;     public static int totalsteps = 8;     int i, g = 0, result = 0;     string result = "";     public static contentvalues values = new contentvalues();     xmlparserhandlerfinal handler;      public static final uri apn_table_uri = uri             .parse("content://telephony/carriers");     public static string base_url = "https://www.mysettings.com/";     public static inputstream stream = null;     updateactivity update;     public static string status;      /** called when activity first created. */     @suppresslint("newapi")     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         int version = android.os.build.version.sdk_int;         tm = (telephonymanager) getsystemservice(telephony_service);         update = new updateactivity();         namearr = update.getnamearr();         apnarr = update.getapnarr();         mmscarr = update.getmmscarr();         mmsproxyarr = update.getmmscproxyarr();         mmsportarr = update.getmmsportarr();         proxyarr = update.getmmscproxyarr();         portarr = update.getmmsportarr();         count = update.getcount();         if (apnarr.isempty() || mmscarr.isempty() || mmsportarr.isempty()                 || mmsproxyarr.isempty() || proxyarr.isempty()                 || portarr.isempty()) {             tryagain();         } else if (version < version_codes.ice_cream_sandwich) {              // update apn table             try {                 result = updatetable();             } catch (ioexception e1) {                 // todo auto-generated catch block                 e1.printstacktrace();             }// settings updated atomic call             catch (saxexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (parserconfigurationexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              if (result != -1) {                 status = "success";              } else {                 status = "failure";             }              if (status.equals("success")) {                 completeupdate();             } else if (status.equals("failure")) {                 tryagain();                 // showalert(getstring(r.string.unchanged_net10_dialog));             }          } else {// ics , later versions              // reduce number of steps 6             totalsteps = 6;             setcontentview(r.layout.assist_instructions);     //      string assistupdate = getstring(r.string.instructions_1);     //      charsequence styledtext = html.fromhtml(assistupdate);             textview assisttext = (textview) findviewbyid(r.id.apn_app_text_cta2);     //      assisttext.settext(styledtext);             massistupdatebutton = (button) findviewbyid(r.id.assist_instr_btn);             massistupdatebutton.setonclicklistener(this);          }     }      public void onclick(view v) {         if (v == massistupdatebutton) {              // update button ics , selected             // textview in assist update ui              textview tv = (textview) findviewbyid(r.id.apn_app_text_cta2);             string text = "";             charsequence styledtext = text;             switch (minstructionnumber) {              case 0:                  // retrieve instruction string resource corresponding                 // 2nd set of instructions         //      text = string.format(getstring(r.string.instructions_3),     //                  totalsteps); //      styledtext = html.fromhtml(text);                 // update textview correct set of instructions                 //tv.settext(styledtext);                 // increment instruction number correct instructions                 // string resource can retrieve next time update                 // button pressed                 minstructionnumber++;                 break;              case 1:                 // first set of instructions step step process update                 // apn settings corresponding layout                 //setcontentview(r.layout.screen5); ////                string one_text = string.format(getstring(r.string.one), ////                        totalsteps); ////                charsequence styledtext_one = html.fromhtml(one_text); //              textview 1 = (textview) findviewbyid(r.id.text_one); //              one.settextsize(18); //              one.settext(styledtext_one); //              string two_text = string.format(getstring(r.string.two), //                      totalsteps); //              charsequence styledtext_two = html.fromhtml(two_text); //              textview 2 = (textview) findviewbyid(r.id.text_two); //              two.settextsize(18); //              two.settext(styledtext_two); //              string three_text = string.format(getstring(r.string.three), //                      totalsteps); //              charsequence styledtext_three = html.fromhtml(three_text); //              textview 3 = (textview) findviewbyid(r.id.text_three);         //      three.settextsize(18);             //  three.settext(styledtext_three);                 massistupdatebutton = (button) findviewbyid(r.id.assist_instr_btn);                 massistupdatebutton.setonclicklistener(this);                 minstructionnumber++;                 break;              case 2:                 // second set of instructions step step process update                 // apn settings corresponding layout             //  setcontentview(r.layout.screen6);             //  string four_text = string.format(getstring(r.string.four),         //              totalsteps);         //      styledtext = html.fromhtml(four_text);         //      textview 4 = (textview) findviewbyid(r.id.text_four);         //      four.settextsize(18);         //      four.settext(styledtext);         //      string five_text = string.format(getstring(r.string.five),             //          totalsteps);             //  styledtext = html.fromhtml(five_text);             //  textview 5 = (textview) findviewbyid(r.id.text_five);             //  five.settextsize(18);             //  five.settext(styledtext);         //      string six_text = string.format(getstring(r.string.six), //                      totalsteps); //              styledtext = html.fromhtml(six_text); //              textview 6 = (textview) findviewbyid(r.id.text_six); //              six.settextsize(18); //              six.settext(styledtext); //          //  string seven_text = string.format(getstring(r.string.seven),                 //      totalsteps);             //  styledtext = html.fromhtml(seven_text);             //  textview 7 = (textview) findviewbyid(r.id.text_seven);         //      seven.settextsize(18);         //      seven.settext(styledtext);             //  string eight_text = string.format(getstring(r.string.eight),                 //      totalsteps);             //  styledtext = html.fromhtml(eight_text);             //  textview 8 = (textview) findviewbyid(r.id.text_eight);         //      eight.settextsize(18);         //      eight.settext(styledtext);                  // testing                 result = "success";                 massistupdatebutton = (button) findviewbyid(r.id.assist_instr_btn);                 if (result.equalsignorecase("success")) {                     massistupdatebutton.setonclicklistener(this);                 } else if (result.equalsignorecase("failure")) {                     // // displaying final layout after failure of post-ics                     // settings                     // read result in response ..if success go ahead                     // else load tryagain screen          //          setcontentview(r.layout.tryagain);         //          setcontentview(r.layout.tryagain);                     string tryagaintext = "";                     charsequence styledtryagaintext;  //                  tryagaintext = string.format( //                          getstring(r.string.tryagain_text1), totalsteps); //                  styledtryagaintext = html.fromhtml(tryagaintext); //                  textview tryagain1 = (textview) findviewbyid(r.id.tryagain_text1); //                  tryagain1.settext(styledtryagaintext);  //                  tryagaintext = string.format( //                          getstring(r.string.tryagain_text2), totalsteps); //                  styledtryagaintext = html.fromhtml(tryagaintext); //                  textview tryagain2 = (textview) findviewbyid(r.id.tryagain_text2); //                  tryagain2.settext(styledtryagaintext); // //                  tryagaintext = string.format( //                          getstring(r.string.tryagain_text3), totalsteps); //                  styledtryagaintext = html.fromhtml(tryagaintext); //                  textview tryagain3 = (textview) findviewbyid(r.id.tryagain_text3); //                  tryagain3.settext(styledtryagaintext);                  }                  minstructionnumber++;                 break;             case 3:                 // final set of instructions              //  setcontentview(r.layout.assist_instructions_update);             //  string last_instr_text = string.format(         //              getstring(r.string.instructions_5), totalsteps);             //  styledtext = html.fromhtml(last_instr_text);             //  textview last_text = (textview) findviewbyid(r.id.apn_app_text_cta3);             //  last_text.settext(styledtext);  //      //      string last_instr_text1 = string.format( //                      getstring(r.string.thatsit), totalsteps); //              styledtext = html.fromhtml(last_instr_text1); //              textview last_text1 = (textview) findviewbyid(r.id.thatsit); //              last_text1.settext(styledtext);                  string mreadagaintext = string                         .format(getstring(r.string.read_again_text));                 styledtext = html.fromhtml(mreadagaintext);                  massistinstrbutton = (button) findviewbyid(r.id.assist_instr_btn);             //readagainbutton = (button) findviewbyid(r.id.read_again_btn);              //readagainbutton.settext(styledtext);                 massistinstrbutton.setonclicklistener(this);         //mreadagainbutton.setonclicklistener(this);             }         } else if (v == massistinstrbutton) {             // "let's this" button in final instructions screen ics ,             // selected             values = getvalues();             startactivity(new intent(settings.action_apn_settings));             try {                 shownotification();             } catch (saxexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (parserconfigurationexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             finish(); 

you cannot compare views objects that. typically compare button id's so:

public void onclick(view v) {     switch(v.getid()) {     case r.id.assist_instr_btn:     case r.id.button2:     } } 

edit: suggest read testing object equality in java. using == fine primitives, not objects.


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 -