I want to make it so that when I click a Button, it takes the text from the EditText
and adds it to an SQLiteDatabase
. I've read it somewher开发者_Go百科e before, but I forgot how to do it.
How about grabbing the text, converting it to a String and putting it into the query
String TableName = "ComplicatedTableNameHere";
EditText editText1 = (EditText) findViewById(R.id.EditTextIDhere);
String editTextString1 = editText1.getText().toString();
BROKEN DOWN
String TableName = "ComplicatedTableNameHere";
//sets the table name as a string so you can refer to TableName instead of writing out your table name everytime
EditText editText1 = (EditText) findViewById(R.id.EditTextIDhere);
//gets the text from your edit text fieldfield
//editText1 = your edit text name
//EditTextIDhere = the id of your text field
String editTextString1 = editText1.getText().toString();
//sets the edit text as a string
//editText1 is the name of the Edit text from the (EditText) we defined above
//editTextString1 = the string name you will refer to in future
then use
/* Insert data to a Table*/
myDB.execSQL("INSERT INTO "
+ TableName
+ " (Column_Name, Column_Name2, Column_Name3, Column_Name4)"
+ " VALUES ( "+EditTextString1+", 'Column_Value2','Column_Value3','Column_Value4');");
Hope this helps some what...
You have to look at the following functions:
To implement the eveent Listener :
onClick()
To get Text from textedit
getText()
To add data into SQLite :
insert()
Docs are the best guide....
You can use this:
mydatebase.execSQL(
"INSERT INTO xxx (name,number,age) VALUES ('"+YOUR_STRING_DATA+"',123456789,22)"
);
精彩评论