android - Java code to retrieve data from database using two input values -


the program gets input rollno , name , displays address , marks based on it. output marks , address null instead of value stored in databse. php code works fine. >

public class mainactivity extends appcompatactivity implements view.onclicklistener { private edittext edittext; private edittext edittext2;  private button buttonget; private textview textviewresult; private progressdialog loading;  @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); edittext = (edittext) findviewbyid(r.id.edittext); edittext2 = (edittext) findviewbyid(r.id.edittext2); buttonget = (button) findviewbyid(r.id.buttonget); textviewresult = (textview) findviewbyid(r.id.textviewresult); buttonget.setonclicklistener(this); }  private void getdata() { string rollno = edittext.gettext().tostring().trim(); if (rollno.equals("")) { toast.maketext(this, "please enter rollno", toast.length_long).show();             return; } string name = edittext2.gettext().tostring().trim(); if (name.equals("")) { toast.maketext(this, "please enter name", toast.length_long).show(); return; } loading = progressdialog.show(this,"please wait...","fetching...",false,false); string url = http://192.14.6.113/getdata.php?rollno="+rollno+" & name="+name; stringrequest stringrequest = new stringrequest(url, new response.listener<string>() { @override public void onresponse(string response) { loading.dismiss(); showjson(response); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { toast.maketext(mainactivity.this,error.getmessage().tostring(),toast.length_long).show(); } });  requestqueue requestqueue = volley.newrequestqueue(this);  requestqueue.add(stringrequest); }  private void showjson(string response){ tring address=""; string marks = ""; try { jsonobject jsonobject = new jsonobject(response); jsonarray result = jsonobject.getjsonarray(config.json_array); jsonobject collegedata = result.getjsonobject(0); address = collegedata.getstring(config.key_address); marks = collegedata.getstring(config.key_marks); } catch (jsonexception e) { e.printstacktrace(); } textviewresult.settext("address:\t" +address+ "\nmarks:\t"+ marks); }  @override public void onclick(view v) { getdata();     } } 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -