Android Search function using a string from an EditText
<p>The Search function in my Android app works. I'm using <code>onSearchRequested()</code>; to invoke the Search function. Now what I'd like to do is not use <code>onSearchRequested()</code>; and pass a string from an <code>EditText</code> to the search method and display the results in a List. Here's my search as it's working when <code>onSearchRequested</code> is called:</p>

<p><code>SearchPage</code> Activity:</p>

<pre><code>    DBHelper = new DBAdapter(this);
    DBHelper.open();
    Intent intent = getIntent();

    if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
        String query = intent.getStringExtra(SearchManager.QUERY);
        showResults(query);

    }
    //--- END onSearchRequested


private void showResults(String query) {
    Cursor cursor = DBHelper.searchDB(query);
    startManagingCursor(cursor);
    String[] searchFrom = new String[] { DBAdapter.KEY_YEAR,
            DBAdapter.KEY_MAKE, DBAdapter.KEY_MODEL };
    int[] displayHere = new int[] { R.id.rYearTV, R.id.rMakeTV,
            R.id.rModelTV };

    final SimpleCursorAdapter records = new SimpleCursorAdapter(this,
            R.layout.record_2, cursor, searchFrom, displayHere);

    setListAdapter(records);
</code></pre>

<p><code>DBAdapter</code> Activity:</p>

<pre><code>//--- GET RECORDS FOR SEARCH
    public Cursor searchDB(String query) { 

    String[] parts = query.split(" "); 

    String queryString = ""; 
    for(int i = 0; i &lt; parts.length; i++) { 
        queryString += KEY_YEAR + " LIKE '%" + parts[i] + "%' OR "; 
        queryString += KEY_MAKE + " LIKE '%" + parts[i] + "%' OR "; 
        queryString += KEY_MODEL + " LIKE '%" + parts[i] + "%'"; 
        if(i != (parts.length - 1)) { 
            queryString += " OR "; 
        } 
    } 

    return db.query(true, DB_TABLE,  
        new String[] { KEY_ROWID, KEY_SDATE, KEY_YEAR, KEY_MAKE, KEY_MODEL },  
        queryString, null, null, null, null, null); 
}
//--- END Get Records for Search
</code></pre>

<p>I'd like to pass a String into the search function <code>String searchData = searchEditText.getText().toString();</code> and have the search function go to work on the passed string by pressing a "Search" button. Can someone help get me started?</p>
