java - [SOLVED]How to use split string to search and populate to listview -



java - [SOLVED]How to use split string to search and populate to listview -

i'm newbie in android programming. tried searching in net can't find possible solution.

my programme below utilize split inputted string using comma (",") *search database using split string *populate listview

my problem search using lastly element in string array(herbalsuggesstionsarray) want populate matches (symptoms2) using element in string array

for illustration :

user input: flu, cough

listview: possible illness symptoms of "flu" , "cough"

sorry grammar guys , in advance. more powerfulness stackoverflow community

searchtext = (edittext) findviewbyid (r.id.searchtexths); string[] herbalsuggesstionsarray = searchtext.gettext().tostring().trim().split("\\s*,\\s*"); for(int x= 0; x<herbalsuggesstionsarray.length;x++){ cursor = db.rawquery("select _id, name, symptoms2 hsdisease symptoms2 like?", new string[]{""+ herbalsuggesstionsarray[x]} ); adapter = new simplecursoradapter( this, r.layout.herbalsuggestion_list_item, cursor, new string[] {"name", "symptoms2"}, new int[] {r.id.hsname, r.id.hssymptoms} ); setlistadapter(adapter); searchtext.gettext().clear(); }

currently query db , create new adapter every simptom.

instead fetch results symptoms @ 1 time , create adapter.

string[] herbalsuggesstionsarray = searchtext.gettext().tostring().trim().split("\\s*,\\s*"); string query = "select _id, name, symptoms2 hsdisease symptoms2 ?" // append many clauses necessary for(int x= 0; x<herbalsuggesstionsarray.length - 1; x++) { query += " or symptoms2 ?"; } cursor = db.rawquery(query, herbalsuggesstionsarray); adapter = new simplecursoradapter( this, r.layout.herbalsuggestion_list_item, cursor, new string[] {"name", "symptoms2"}, new int[] {r.id.hsname, r.id.hssymptoms} ); setlistadapter(adapter); searchtext.gettext().clear();

java android eclipse android-activity

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -