将文本从EditText添加到SQLite

问题描述 投票:0回答:3

我想这样做,当我点击一个按钮时,它会从EditText获取文本并将其添加到SQLiteDatabase。我之前在某处读过它,但我忘记了怎么做。

android sqlite button android-edittext
3个回答
0
投票

你必须看看以下功能: 要实现事件监听器: qazxsw poi

从textedit获取文本 onClick()

要将数据添加到SQLite中: getText()

文件是最好的指南....


2
投票

如何抓取文本,将其转换为String并将其放入查询中

insert()

破产了

String TableName = "ComplicatedTableNameHere";  
EditText editText1 = (EditText) findViewById(R.id.EditTextIDhere); 
String editTextString1 = editText1.getText().toString();  

然后用

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

希望这有助于一些......


0
投票

你可以用这个:

       /* 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');");
© www.soinside.com 2019 - 2024. All rights reserved.