Insert into sql Db from EditText Fields with Button?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Insert into sql Db from EditText Fields with Button?

Postby iloveDroid » Fri Dec 25, 2009 9:36 pm

Hello im working on an app with sqlite. I have 4 EditText boxes that I want to be inserted into the sql db after some one has filled out the EditText boxes and clicked a button.

How would I do this.

thanks
iloveDroid
Freshman
Freshman
 
Posts: 6
Joined: Mon Dec 21, 2009 3:47 am

Top

Postby achie1266 » Fri Dec 25, 2009 9:59 pm

hello,

you need to check out the notepad tutorial provided by google. It has a very good example which shows exactly what you are trying to do.
http://developer.android.com/resources/ ... index.html

you have to implement onClckListener and grab the textfrom edit textboxes, but the tutorial in go in detail how you can do that and push it into database. It will also show you how to save the text if you want to store a partially completed edit text before user clicks on button.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby iloveDroid » Fri Dec 25, 2009 10:14 pm

achie1266 wrote:hello,

you need to check out the notepad tutorial provided by google. It has a very good example which shows exactly what you are trying to do.
http://developer.android.com/resources/ ... index.html

you have to implement onClckListener and grab the textfrom edit textboxes, but the tutorial in go in detail how you can do that and push it into database. It will also show you how to save the text if you want to store a partially completed edit text before user clicks on button.


Thanks, ill check it out, the official documentation is usually very confusing.
iloveDroid
Freshman
Freshman
 
Posts: 6
Joined: Mon Dec 21, 2009 3:47 am

Postby achie1266 » Fri Dec 25, 2009 10:18 pm

yeah sometimes the documentation misses detailed explanation which can be a problem when we start developing but this example has everything that you need and has the complete solution for it too.
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Postby iloveDroid » Sat Dec 26, 2009 12:51 am

The notepad tutorials Google has are rubbish, does any one have a snippet or mind showing me some example code?

I know how to create SQlite db's etc. I simply want to insert data into a DB_TABLE rows, it has 4 different fields in the database for the user to enter their info. I want to insert/update on a button click.

I think im going to have to write Google a letter about there crappy reference and manual for Android....

Thanks to any one who can help...
iloveDroid
Freshman
Freshman
 
Posts: 6
Joined: Mon Dec 21, 2009 3:47 am

Postby achie1266 » Sat Dec 26, 2009 6:59 am

iloveDroid wrote:The notepad tutorials Google has are rubbish, does any one have a snippet or mind showing me some example code?

I know how to create SQlite db's etc. I simply want to insert data into a DB_TABLE rows, it has 4 different fields in the database for the user to enter their info. I want to insert/update on a button click.

I think im going to have to write Google a letter about there crappy reference and manual for Android....

Thanks to any one who can help...

May be you should have gone through the tutorial carefully before blaming google. Documentation might be bad in some areas but what you are looking for is available in the notepad tutorial example http://developer.android.com/resources/ ... d-ex1.html
there they use the method createNote. so if you have seen the NotesDbAdapter class there are methods in it for creating tables, feeding data and updating data.
The reference for all those classes and methods is also available in google docs
http://developer.android.com/reference/ ... abase.html
If you still think that you can't find them then this is how you normally insert data. You need to create a contentValues object and pass them as maps
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public long addPerson(Person p){
  2.  
  3.         ContentValues values = new ContentValues();
  4.  
  5.         values.put("_id", p.getId());
  6.  
  7.         values.put("name", p.getName());
  8.  
  9.         values.put("ssn", p.getSsn());
  10.  
  11.         return db.insert("people_table", null, values);
  12.  
  13. }
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
hope this helps you
achie
User avatar
achie1266
Master Developer
Master Developer
 
Posts: 223
Joined: Mon Nov 09, 2009 10:56 pm
Location: Denver

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests