Cin Cin - 1 year ago 100
Android Question

How to search a String value in Sqlite?

I am working on a project and I have little understanding in sqlite. I am working on android application for searching a name from sqlite local database.
I want to grap a text (name) from the editText box and then do query in sqlite.
I found out how to grap a text from the editText box -

EditText txtname = (EditText)findViewById(;
String name = txtname.getText().toString();

From my research, I found this is how you do query in sqlite -

SELECT * FROM Customers

Since, I don't know what user will search in the editText box.

How can I do query that user entered in the editText box to the sqlite database.


Answer Source

I'm not sure what you are asking but I guess it's how to pass the name to the query.

Use SQLiteDatabase.query() with selection arguments, for example

db.query("Customers", null, "City LIKE ?", new String[] { "%" + name + "%" }, null, null, null);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download