android - Get values from database and show it in text view? -


package as.d.d;  import java.util.list; import android.app.activity; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.toast;  public class add extends activity implements onclicklistener{       button b1,b2;     edittext e2,e3;     textview t1;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.add);          b1=(button)findviewbyid(r.id.button1);         b2=(button)findviewbyid(r.id.button2);         e2=(edittext)findviewbyid(r.id.edittext2);         e3=(edittext)findviewbyid(r.id.edittext3);         t1=(textview)findviewbyid(r.id.atextview1);          b1.setonclicklistener(this);         b2.setonclicklistener(this);           databasehandler db = new databasehandler(this);         list<studentinfo> studentinfo = db.getallstudentinfo();          (studentinfo cn : studentinfo){              t1.settext("id:"+(cn.getid()+1));         }    }      @override     public void onclick(view v) {           if(v==b2){             startactivity(new intent(add.this, fdactivity.class));         }         else if(v==b1){              string s2=e2.gettext().tostring();             string s3=e3.gettext().tostring();              if(s2.trim().equals("")||s3.trim().equals("")){                  toast.maketext(getapplicationcontext(), "please submit student information",toast.length_short).show();                  }                 else{                 databasehandler db = new databasehandler(this);                 log.d("insert: ", "inserting ..");                 db.addcontact(new studentinfo(s2,s3));                 log.d("reading: ", "reading contacts..");                 list<studentinfo> studentinfo = db.getallstudentinfo();                 (studentinfo cn : studentinfo){                     t1.settext("id:"+(cn.getid()+1));             }}}}} 

in add class using textview autogenerated student id(numerical(int) , 2 text field submit student name , phone number database pressing button.here student id,name , phone number submitted succesfully.

in addmark class use autocomplete textview showing names submitted add class.when select name suppose farhan(which submitted database , id 4 , phone number 99876 stored in database) want see id , phone number in 2 textview(textview t1,t2;)?

package as.d.d;  import java.util.arraylist; import java.util.list;  import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.arrayadapter; import android.widget.autocompletetextview; import android.widget.textview; import android.widget.toast;  public class addmark extends activity{      autocompletetextview a1;     textview t1,t2;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.addmark);          a1=(autocompletetextview)findviewbyid(r.id.autocompletetextview1);         t1=(textview)findviewbyid(r.id.amtextview1);         t2=(textview)findviewbyid(r.id.amtextview2);             databasehandler db = new databasehandler(this);          final list<studentinfo> studentinfo = db.getallstudentinfo();            final arraylist<string> s1 = new arraylist<string>();           (studentinfo cn : studentinfo) {             s1.add(cn.getname());           }         arrayadapter<string> adapter =  new arrayadapter<string>(this, android.r.layout.simple_dropdown_item_1line,s1);           a1.setthreshold(1);          a1.setadapter(adapter);            a1.setonitemclicklistener(new onitemclicklistener() {              @override             public void onitemclick(adapterview<?> arg0, view arg1, int arg2,                     long arg3) { }         }); 

well first of it's bad idea select students based on not unique. want select name in autocomplete text view , based on show phone nr , id. imagine happen if have 2 or more students same name (which not excluded). should populate autocomplete tv (or combination of somethings) uniquely define record in database. how achieve this, verify when control loses focus , set 2 textviews values need.

a1.setonfocuschangelistener(new onfocuschangelistener() {                public void onfocuschange(view v, boolean hasfocus) {         if(!hasfocus)            //set textviews values need      } }); 

again, keep in mind not recomended select id , phone number (both can unique identifiers db table) based on can repeat in db.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -