android - Alertdialog not shown -


i have activity edittext , (momentary 2 buttons). when button pressed, data edittext checked empty or null string. if alertdialog should shown. should repeated until result textedit not empty. works fine long not have further processing in activity. if have have further insructions alertdialog not shown. th step step dubugging shows apllication goes check, creates alertdialog not shown, instead next instruction in code performed. makes no sense. application must stop processing @ point alertdialog shown. once non empty string received should checked against textfile various sql injection strings , raise progressdialog showing progress of test.if test positive should return edittext allow correction of data. far tho behaviour same buttons. believe the best way create own (inner) class these actions. further actions (not yet implented) should be: 1 button call activity asking manual completion of data, others try fetch missing data various internet resources. , show results in activity, allowing selection of correct data. complete data sent database. (one reason testing against sql injection strings)

here code:

public class blahverwaltungdateneingabeactivity extends activity {      public string vtitel=null;  //variable, der der wert des texteingabefeldes zugewiesen werden soll     public string vtitel_1 = null; //variable für stringmanipulation     private edittext input_vtitel; //texteingabefeld     public static boolean inject_2=false;     final context context_1=this;     toast eintoast;  //  private string filename=getstring(r.string.tempfile_fuer_blahdaten); // temporäres file für blahdaten       @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_blahverwaltung_dateneingabe_1);          button manuellbutton = (button) findviewbyid(r.id.manuell_button);         button ofdbbutton = (button) findviewbyid(r.id.blah_button);           //onclicklistener erzeugen          manuellbutton.setonclicklistener(new view.onclicklistener() {               @override             public void onclick(view view) {                  input_vtitel = (edittext) findviewbyid(r.id.blahtitel); //texteingabefeld initialisieren                 vtitel = input_vtitel.gettext().tostring();  //texteingabe string zuweisen                  if (vtitel.equals(null) || vtitel.equals("")) {                     alertdialog.builder adb_1 = new alertdialog.builder(context_1); //alertdialog wenn texteingabe leer                     adb_1.settitle(r.string.nullstring); //alertdialgo titel setzen                     adb_1.setmessage(r.string.nullstring_1); //alertnachricht setzen                     adb_1.setcancelable(false); //kann nicht durch abgebrochen werden                     adb_1.setpositivebutton(r.string.ok, new dialoginterface.onclicklistener() {    //onclicklistener erzeugen                         public void onclick(dialoginterface dialog, int which) {     //activity neu starten                             dialog.dismiss();                             if (build.version.sdk_int >= 11) {     //methode zum neustart in abhängigkeit vom sdk wählen                                 recreate();                             } else {                                 intent in_1 = getintent();                                 overridependingtransition(0, 0);                                 in_1.addflags(intent.flag_activity_no_animation);                                 finish();                                  overridependingtransition(0, 0);                                 startactivity(in_1);                             }                          }                     });                     alertdialog ad_1 = adb_1.create();     //alertdialig erzeugen                     ad_1.show();                                              //alertdialog anzeigen                 }                 injectiondialog id_1= new injectiondialog(blahverwaltungdateneingabeactivity.this);                 id_1.execute(vtitel);                 try {                     inject_2=id_1.get();                 } catch (interruptedexception e) {                     e.printstacktrace();                 } catch (executionexception e) {                     e.printstacktrace();                 }             }   //                vtitel_1 = vtitel.replace(" ", "+"); //leerzeichen durch "+" ersetzen /*                 try {                     outputstream_1 = openfileoutput(filename, context.mode_private);                     outputstream_1.write(vtitel.getbytes());                     outputstream_1.close();                 } catch (filenotfoundexception e) {                     e.printstacktrace();                 } catch (ioexception e) {                     e.printstacktrace();                 } catch (nullpointerexception e) {                     e.printstacktrace();                 } */              });         }        @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.blahverwaltung_dateneingabe, menu);         return true;     }  } 

if provide help, please explain as possible, i'm java/android newbie , not understand doing. learning books , internet sources not helpfull. i'm able adopt provided solutions want understand why done way , code doing.

btw: mentioned above data may sent interent, how can make sure no html hacking, cross site scripting java script, php attack code in data when sent? there comon strings can check data strings against?

ok, no 1 answered questions far. try myself. above code sample have rewritten , did lot of step step debugging on understand behaviour of android program exectuion , variables initialisation , assignment.

i'll explain understood far. if there errors, please correct me.

here new code, still not complete , still contains useless "debugging", causing endless loops code added understand how program exectuion , variables assignment work.

public class blahverwaltungdateneingabeactivity extends activity implements onclicklistener {      public string vtitel_1 = null; //variable für stringmanipulation     public static boolean inject_2=false;     private button manuell_button;     private button ofdb_button;     context context_1=blahverwaltungdateneingabeactivity.this;     toast eintoast;  //  private string filename=getstring(r.string.tempfile_fuer_blahdaten); // temporäres file für blahdaten       @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_blahverwaltung_dateneingabe_1);          manuell_button = (button) findviewbyid(r.id.manuell_button);         manuell_button.setonclicklistener(this);          ofdb_button = (button) findviewbyid(r.id.ofdb_button);         ofdb_button.setonclicklistener(this);      }      public void onclick(view v) {         edittext input_vtitel =(edittext) findviewbyid(r.id.blahtitel);          string vtitel = input_vtitel.gettext().tostring();          if (vtitel.length() == 0) {             new builder(this)                     .settitle(r.string.nullstring)                     .setmessage(r.string.nullstringtext)                     .setcancelable(false)                     .setneutralbutton(r.string.ok, null)                     .show();             return;         } else {             builder adb_2 = new builder(this);             adb_2.settitle(r.string.sqlinjectionpruefung)                  .setcancelable(false)                  .seticon(r.drawable.sand_glass_23654_150)                  .setneutralbutton(r.string.ok, null);             alertdialog ad_2 = adb_2.create();             ad_2.show();             button okbutton = ad_2.getbutton(alertdialog.button_neutral);             okbutton.setenabled(false);             inject_2=injectioncheck.injectioncheckresult(context_1, vtitel);             okbutton.setenabled(true);             okbutton.setonclicklistener(new onclicklistener() {                  @override                 public void onclick(view v_1) {                     toast.maketext(videoverwaltungdateneingabeactivity.this, "testtest", toast.length_long).show();                 }             });             toast.maketext(this, "testtesttest", toast.length_long).show();             if (inject_2) {                 okbutton.performclick();                 new builder(this)                         .settitle(r.string.sqlinjectionresult)                         .setmessage(r.string.sqlinjectionresulttext)                         .setcancelable(false)                         .setneutralbutton(r.string.ok, null)                         .show();                 return;             }         }         toast.maketext(this, "test", toast.length_long).show();       }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.menu_blahverwaltung_dateneingabe, menu);         return true;     }  } 

first change, i'm implementing onclicklistener activity.

 public class blahverwaltungdateneingabeactivity extends activity implements onclicklistener { 

the advantage: not need create new instance of onclicklistener every button.

second change, have button independent onclick method. advantage: code stuff identical activity buttnos can put here. not matter button clicked code in method executed all activity buttons.

later have check button clicked if (v == manuell_button)... , can put button specific code there. (i hope work)

ok, lets assume have nothing entered in edittext field , click button. happen now?

the program exectutes

string vtitel = input_vtitel.gettext().tostring(); 

which result in "" empty string.

next go

if (vtitel.length() == 0) 

and because have empty string length = 0 execute instructions there.

new builder(this)         .settitle(r.string.nullstring)         .setmessage(r.string.nullstringtext)         .setcancelable(false)         .setneutralbutton(r.string.ok, null)         .show(); return; 

this code seems executed en block. although set breakpoint on return instruction never stopped there. not show alerdialog yet, instead jumps end of onclick method. invokes view.java, without showing dialog, handler.java - still not showing dialog , looper.java , here dialog displayed. because haven't implemented onclicklstener dialog button clicking button dismiss dialog without further action , return activity.

now lets assume entered textedit field. program go "else" tree of "if (vtitel.length() == 0)" instruction. execute all appropiate steps tree without showing alertdialog perform appropiate actions remaining code in activity , again invoke view.java, handler.java , looper.java before showing dialog.

this makes impossible create behaviour this:

  1. raise dialog
  2. stop program execution , wait user action
  3. perform further code depending on user response

in code user input checked against file injection strings. original intention , display dialog while check performed automatically dismiss dialog , continue program depending on result of check. file small , not cause delay tried adding thread.sleep() instruction or putting check in loop , let run 100 times. not matter result same instruction performed before showing alertdialog. in case alertdialog useless. possibility have been progressdialog here have similiar problems. progressdialog runs independent activity, means while progressdialog runnung activity performs further actions. activity needs results progressdialog. second problem, there no easy way pass results of progressdialog activity.the progressdialog.get() method works prevents progressdialog showing.the onpostexecute method not usable, seems not designed pass results activity although performed in activity thread. here i'm stuck @ moment. looks there no easy way achieve behaviour want , have find ways deal behaviour of android programs without losing of functionality want.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -