android - how to display json object in textview -


this activity .. plss .. doesn't appear on textview ..what i'm trying here displaying profile of admin upon clicking profile option in navigation drawer .. in advance ..

please kindly comment suggestion on how solve ..

    public class profile extends fragment{      int success; view profile; jsonparser jsonparser = new jsonparser(); jsonobject json; textview tvname,tvnumber,tvemail,tvusername,tvpass,tvaddress; string adminname, adminnumber,adminemail,adminusername,adminpassword,adminaddress;  private static final string profile_url =   "http://jcasim.5gbfree.com/project/jcasim_api/profile.php"; private static final string tag_success = "success"; // private static final string tag_id = "id";    public profile (){} @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     // todo auto-generated method stub     view profile = inflater.inflate(r.layout.profile, container,false);     tvname = (textview)profile.findviewbyid(r.id.tvadminname);     tvnumber = (textview)profile.findviewbyid(r.id.tvadminnumber);     tvemail = (textview)profile.findviewbyid(r.id.tvadminemail);     tvusername = (textview)profile.findviewbyid(r.id.tvadminusername);     tvpass = (textview)profile.findviewbyid(r.id.tvadminpassword);     tvaddress = (textview)profile.findviewbyid(r.id.tvadminaddress);      new profile().execute();     return profile; } class profile extends asynctask<string, string, string>{     @override     protected string doinbackground(string... arg0) {         // todo auto-generated method stub         string addminobject ="";         list<namevaluepair> params = new arraylist<namevaluepair>();         params.add(new basicnamevaluepair("addminobject", addminobject));         json = jsonparser.makehttprequest(profile_url, "post",params);         try {             // json success tag             success = json.getint(tag_success);         } catch (jsonexception e) {             e.printstacktrace();         }         return null;      }     @override     protected void onpostexecute(string result) {         // todo auto-generated method stub         if (success == 1){             try {                 jsonarray myarr = json.getjsonarray("addminobject");                  for(int =0; i<myarr.length();i++){                     jsonobject s = myarr.getjsonobject(i);                      string adminname = s.getstring("completename");                     string adminnumber = s.getjsonobject("1").getstring("number");                     string adminemail = s.getjsonobject("2").getstring("email");                     string adminusername = s.getjsonobject("3").getstring("username");                     string adminpassword = s.getjsonobject("4").getstring("password");                     string adminaddress = s.getjsonobject("5").getstring("address");                       tvname.settext(adminname);                     tvnumber.settext(adminnumber);                     tvemail.settext(adminemail);                     tvusername.settext(adminusername);                     tvpass.settext(adminpassword);                     tvaddress.settext(adminaddress);                 }              } catch (jsonexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              }     } 

and here's my json ..

    {"success":1,"addminobject":[{"completename":"joenevie v.almonte","number":"09167801027","email":"devied24@gmail.com","username":"admin","password":"pass","address":"sa puso ng mahal ko .. :)"}]} 

you doing wrong. should instead.

   string adminname = s.getstring("completename");    string adminnumber = s.getstring("number");    string adminemail = s.getstring("email");    string adminusername = s.getstring("username");    string adminpassword = s.getstring("password");    string adminaddress = s.getstring("address"); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -