android - press the save button EditText value is stored in to the database -
i have 4 edittext , 2 buttons namely, save , review button.
if press save button edittext value stored in database , on clicking review button saved value in database listed in listview.
how done please explain me.
import android.content.context; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; import android.provider.basecolumns; public class databasehelper extends sqliteopenhelper { public databasehelper(context context) { super(context, "medicinepill", null, 1); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table if not exists names3 (" + basecolumns._id + " integer primary key autoincrement, first varchar, last varchar ,dose2 varchar ,dose3 varchar)"); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // steps upgrade database new version ... } } //this database class in add insert data database import android.app.activity; import android.os.bundle; import android.view.view; import android.widget.button; import android.widget.edittext; public class medical extends activity { button addmedicine,reviewmedicine; edittext dose1,dose2,dose3; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); addmedicine = (button)findviewbyid(r.id.add); reviewmedicine = (button)findviewbyid(r.id.rev); dose1 = (edittext)findviewbyid(r.id.edit1); addmedicine.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string s1 = dose1.gettext().tostring(); // todo auto-generated method stub } }); } }
//and activity class
how add edittext value in database pls body me!!!!!!!!
you need create method in databasehelper class takes in 4 strings , adds them database.
then in onclick() method in medical activity class can string values 4 edittext fields , call method these values.
i recommend going through notepad tutorial. should provide example of want do.
Comments
Post a Comment