I am trying to implement a LIke query to get results from database according to user input in search box.
Below is the method I am using to get the results
public Cursor getSearchResults(String query) {
// TODO Auto-generated method stub
//Toast.makeText(myContext, "dhfhgjhfghdfjghxdf", Toast.LENGTH_LONG).show();
String[] args={query};
return(getReadableDatabase().rawQuery("SELECT _id,chapter FROM chapters WHERE chapter LIKE '%query%'", args));
}
Here the %query% is coming from search action im my searchResultActivity.java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.search_query_results);
mQueryText = (ListView) findViewById(R.id.txt_query);
Toast.LENGTH_LONG).show();
// Get the intent, verify the action and get the query
Intent intent = getIntent();
String query = intent.getStringExtra(SearchManager.QUERY);
Toast.makeText(SearchResultsActivity.this,query, Toast.LENGTH_LONG).show();
dbBookHelper = new BooklistHelper(this);
ourCursor = dbBookHelper.getSearchResults(query);
startManagingCursor(ourCursor);
adapter = new AuthorAdapter1(ourCursor);
mQueryText.setAdapter(adapter);
//mQueryText.setOnItemClickListener(onListClick);
}
But i am getting this error "cannot bind argument at index 1 because the index is out of range android. the statement has 0 argument".
Please help me in this.
Let me know if you need more information.
Thanks In advance..:)