Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting an ArrayAdapter to CursorAdapter for use in a SearchView
    primarykey
    data
    text
    <p>How can I convert an <code>ArrayAdapter&lt;String&gt;</code> of static data into a <code>CursorAdapter</code> for using Suggestion Listener in <code>SearchView</code>? I have constructed the <code>ArrayAdapter&lt;String&gt;</code> from static data (<code>allString</code>)</p> <pre><code>ArrayAdapter&lt;String&gt; searchAdapter = new ArrayAdapter&lt;String&gt;(context, R.layout.listitem, allString); </code></pre> <p>and I use it for an <code>MultiAutoCompleteTextView</code> which works fine in devices with API level less than 11</p> <pre><code>MultiAutoCompleteTextView findTextView.setAdapter(searchAdapter); </code></pre> <p>However my target API is level is 11 and for API>10 I use an <code>ActionBar</code> within which I would like to have a SearchView instead. </p> <p>Here's what I have tried: It does show the <code>ActionBar</code> with the embedded <code>SearchView</code> but does not give any suggestions as it would in the <code>MultiAutoCompleteTextView</code>.</p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); if (android.os.Build.VERSION.SDK_INT &gt; 10){ inflater.inflate(R.menu.menu11, menu); searchView = (SearchView) menu.findItem(R.id.MENU_SEARCH).getActionView(); int[] to = {0}; CursorAdapter cursorAdapter = new SimpleCursorAdapter(context, R.layout.listitem, null, allBusStopString, to); searchView.setSuggestionsAdapter(cursorAdapter); searchView.setOnSuggestionListener(new OnSuggestionListener() { @Override public boolean onSuggestionClick(int position) { String selectedItem = (String)cursorAdapter.getItem(position); Log.v("search view", selectedItem); return false; } @Override public boolean onSuggestionSelect(int position) { return false; } }); }else{ inflater.inflate(R.menu.menu, menu); } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload