android - variable textview not working -


i have code , cant variable string here

private void location() {     layoutinflater layoutinflater = layoutinflater.from(this);     view promptview = layoutinflater.inflate(r.layout.alquila, null);     textview tv = (textview) promptview.findviewbyid(r.id.gen);     random r = new random();     int = r.nextint(101);     tv.settext(i +"");     final string passwd = tv.gettext().tostring();     final alertdialog alertd = new alertdialog.builder(this).create();      button btnadd1 = (button) promptview.findviewbyid(r.id.button3);       btnadd1.setonclicklistener(new view.onclicklistener() {         public void onclick(view v) {             new sendpostrequest().execute();             toast.maketext(login.this, passwd, toast.length_long).show();             // btnadd1 has been clicked             alertd.dismiss();         }     });      alertd.setview(promptview);      alertd.show(); } 

and need variable string "passwd" to...

public class sendpostrequest extends asynctask<string, void, string> {      protected void onpreexecute(){}      protected string doinbackground(string... arg0) {          try {              url url = new url("https://www.domain.org/file.php"); // here              jsonobject postdataparams = new jsonobject();             postdataparams.put("mensajearea", passwd);             log.e("params",postdataparams.tostring());              httpurlconnection conn = (httpurlconnection) url.openconnection();             conn.setreadtimeout(15000 /* milliseconds */);             conn.setconnecttimeout(15000 /* milliseconds */);             conn.setrequestmethod("post");             conn.setdoinput(true);             conn.setdooutput(true);              outputstream os = conn.getoutputstream();             bufferedwriter writer = new bufferedwriter(                     new outputstreamwriter(os, "utf-8"));             writer.write(getpostdatastring(postdataparams));              writer.flush();             writer.close();             os.close();              int responsecode=conn.getresponsecode();              if (responsecode == httpsurlconnection.http_ok) {                  bufferedreader in=new bufferedreader(new                         inputstreamreader(                         conn.getinputstream()));                  stringbuffer sb = new stringbuffer("");                 string line="";                  while((line = in.readline()) != null) {                      sb.append(line);                     break;                 }                  in.close();                 return sb.tostring();              }             else {                 return new string("false : "+responsecode);             }         }         catch(exception e){             return new string("exception: " + e.getmessage());         }      } 

here --> postdataparams.put("mensajearea", passwd);

help, i've been trying hours without success...

something that

public class sendpostrequest extends asynctask<string, void, string> {      private string passwd;     public sendpostrequest(string pass) {         super();         this.passwd = pass;     }      protected void onpreexecute() {     }      protected string doinbackground(string... arg0) {          try {              url url = new url("https://www.domain.org/file.php"); // here              jsonobject postdataparams = new jsonobject();             postdataparams.put("mensajearea", passwd);             log.e("params", postdataparams.tostring());              httpurlconnection conn = (httpurlconnection) url.openconnection();             conn.setreadtimeout(15000 /* milliseconds */);             conn.setconnecttimeout(15000 /* milliseconds */);             conn.setrequestmethod("post");             conn.setdoinput(true);             conn.setdooutput(true);              outputstream os = conn.getoutputstream();             bufferedwriter writer = new bufferedwriter(                     new outputstreamwriter(os, "utf-8"));             writer.write(getpostdatastring(postdataparams));              writer.flush();             writer.close();             os.close();              int responsecode = conn.getresponsecode();              if (responsecode == httpsurlconnection.http_ok) {                  bufferedreader in = new bufferedreader(new                         inputstreamreader(                         conn.getinputstream()));                  stringbuffer sb = new stringbuffer("");                 string line = "";                  while ((line = in.readline()) != null) {                      sb.append(line);                     break;                 }                  in.close();                 return sb.tostring();              } else {                 return new string("false : " + responsecode);             }         } catch (exception e) {             return new string("exception: " + e.getmessage());         }      } } 

create task of constructor , set passwd

in onclick:

btnadd1.setonclicklistener(new view.onclicklistener() {     public void onclick(view v) {         new sendpostrequest(passwd).execute();         toast.maketext(login.this, passwd, toast.length_long).show();         // btnadd1 has been clicked         alertd.dismiss();     } }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -