hectichavana
hectichavana

Reputation: 1446

Android: Select Query SQLite for ListView

I'm using this method to display a table and its content from SQLite on a ListView:

listView.setAdapter(new MySimpleCursorAdapter(this, R.layout.listitems,
                managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
                        Database.Project.NAME), new String[] { BaseColumns._ID,
                        Database.Project.C_PROJECTTITLE,
                        Database.Project.C_SMALLIMAGE, Database.Project.C_PROJECTDESCRIPTION, Database.Project.C_ORGANIZATIONTITLE, Database.Project.C_DONATIONAMOUNT, Database.Project.C_KEYWORD, Database.Project.C_PRICE, Database.Project.C_SHORTCODE}, null, null, null),
                new String[] { Database.Project.C_PROJECTTITLE,
                        Database.Project.C_SMALLIMAGE, Database.Project.C_PROJECTDESCRIPTION, Database.Project.C_ORGANIZATIONTITLE, Database.Project.C_DONATIONAMOUNT}, new int[] {
                        R.id.txt_title, R.id.image, R.id.txt_list_desc, R.id.txt_org, R.id.btn_amount}));

Now I'm wondering how am I able to do this:

For example I want to display only Database.Project.C_PROJECTTITLE which contains the word 'Health' in its column.

So only the PROJECTS whose PROJECTTITLE contain the word 'Health' will show up on the list.

It doesn't have to be EQUAL 'Health', so the PROJECTTITLE with the name for example 'Health/Bio' also appears on the list. How am I able to perform that?

Upvotes: 0

Views: 448

Answers (2)

kosa
kosa

Reputation: 66657

You query should be something like below:

db.query(TABLE_NAME, new String[] {"_id", "yourColumn"},"yourColumn like " + "'%Health%'", null, null, null, null);

Upvotes: 1

Mark Gjøl
Mark Gjøl

Reputation: 1882

If you let the search term be %health% then it should select all rows that contain health.

Upvotes: 0

Related Questions