android - i want to get name column from database and display on spinner -


i want name column database , display on spinner , when click on name must display other row details of name in textview have 1 spinner , 4 textview , want display names in spinner , other details in textview

entry.java:  public class entry extends appcompatactivity {     button btnsbmt1;     spinner spiner2;     edittext milkcaret,amount, amountp,bal;       databasehelper mydb;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_entry);         mydb=new databasehelper(this);          btnsbmt1=(button)findviewbyid(r.id.btnsubmit2);         spiner2=(spinner)findviewbyid(r.id.spinner2);         milkcaret=(edittext)findviewbyid(r.id.txt1_de);         amount=(edittext)findviewbyid(r.id.txt2_de);         amountp=(edittext)findviewbyid(r.id.txt3_de);         bal=(edittext)findviewbyid(r.id.txt4_de);             adddata2();      }        public void adddata2(){         btnsbmt1.setonclicklistener(                 new view.onclicklistener() {                     @override                     public void onclick(view v) {                         boolean inserteddata = mydb.insertdatat(milkcaret.gettext().tostring(),amount.gettext().tostring(),amountp.gettext().tostring(),bal.gettext().tostring());                          if (inserteddata)                             toast.maketext(entry.this, "data inserted", toast.length_short).show();                         else {                             toast.maketext(entry.this, "database error", toast.length_short).show();                         }                      }                 }         );     } } 

databasehelper.java

    public class databasehelper extends sqliteopenhelper {          public static final string database_name="sales.db";         public static final string table_name1="insert_table";         public static final string table_name2="entry_table";             public static final string col_id="id";         public static final string col_name="name";            public static final string col_caret="caret";         public static final string col_amount="amount";         public static final string col_amount_paid="amount_paid";         public static final string col_balance="balance";             public databasehelper(context context) {             super(context, database_name, null, 1);           }           @override         public void oncreate(sqlitedatabase db) {             db.execsql("create table " + table_name1 + " (id_name integer primary key autoincrement,name text)");             db.execsql("create table " + table_name2 + " (id integer primary key autoincrement,caret integer, amount integer,amount_paid integer,balance integer,foreign key(id) references insert_table(id_name))");          }          @override         public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {             db.execsql("drop table if exists"+table_name1);             db.execsql("drop table if exists "+table_name2);             oncreate(db);          }         public boolean insertdata(string name){             sqlitedatabase db=this.getwritabledatabase();             contentvalues contentvalues =new contentvalues();             contentvalues.put(col_name, name);              long result= db.insert(table_name1,null,contentvalues);             if(result== -1)                 return false;             else                 return true;         }           public boolean insertdatat(string caret,string amount,string amount_paid,string balance ){             sqlitedatabase db=this.getwritabledatabase();             contentvalues contentvalues =new contentvalues();              contentvalues.put(col_caret,caret);             contentvalues.put(col_amount,amount);             contentvalues.put(col_amount_paid,amount_paid);             contentvalues.put(col_balance,balance);              long result= db.insert(table_name2,null,contentvalues);             if(result== -1)                 return false;             else                 return true;         }         } 


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -