Hye..I managed to create search function to search using multiple keywords. The problem is the keywords must be exist inside my database column that i had set. If i search using 3 keywords which is 2 keywords match inside database but 1 more keyword is not exist. The result was displayed nothing.
How could I ignore the non existing keywords?? just take the keywords that exists inside my database only. Means, if the user enter many keywords, system will read only keywords that match inside my database only and it will ignore the keywords that doesn't match. Below is my code.
String s = txtLelaki.getText().toString();
String s = txtLelaki.getText().toString();
String[] words = s.split(" ");
String sql = null;
String where = helper.KEY_LELAKI + " = ?";
String relation = " or ";
String wildcard1 = "'%";
String wildcard2 = "%'";
StringBuilder build = null;
for(int i=0;i<words.length; i++)
{
words[i] = new StringBuilder(wildcard1).append(words[i]).append(wildcard2).toString();
if(i==0)
build = new StringBuilder(where);
else
build.append(relation).append(where);
}
Cursor c = database.query(helper.DB_TABLE_LELAKI, null, build.toString(), words, null, null, null);
if(c!= null)
{
c.moveToFirst();
int soalanColumn = c.getColumnIndex(helper.MASALAH_LELAKI);
int getId = c.getColumnIndex(helper.ID_LELAKI);
if(c.isFirst())
{
do
{
idList.add(c.getLong(getId));
results.add(c.getString(soalanColumn));
}while(c.moveToNext());
}
}
adapter.updateList(results);
listView.setTextFilterEnabled(true);
}//end try
catch(SQLException e)
{
Log.v("caer", e.toString());
}