Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. Add an EditText on top of your listview in its aml layout file. And in your activity/fragment..</p> <pre><code>lv = (ListView) findViewById(R.id.list_view); inputSearch = (EditText) findViewById(R.id.inputSearch); // Adding items to listview adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, R.id.product_name, products); lv.setAdapter(adapter); inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { // When user changed the Text MainActivity.this.adapter.getFilter().filter(cs); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void afterTextChanged(Editable arg0) {} }); </code></pre> <p>The basic here is to add an <strong>OnTextChangeListener</strong> to your edit text and inside its callback method apply filter to your listview's adapter.</p> <p><strong>EDIT</strong></p> <p>To get filter to your custom BaseAdapter you"ll need to implement <strong>Filterable</strong> interface.</p> <pre><code>class CustomAdapter extends BaseAdapter implements Filterable { public View getView(){ ... } public Integer getCount() { ... } @Override public Filter getFilter() { Filter filter = new Filter() { @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults results) { arrayListNames = (List&lt;String&gt;) results.values; notifyDataSetChanged(); } @Override protected FilterResults performFiltering(CharSequence constraint) { FilterResults results = new FilterResults(); ArrayList&lt;String&gt; FilteredArrayNames = new ArrayList&lt;String&gt;(); // perform your search here using the searchConstraint String. constraint = constraint.toString().toLowerCase(); for (int i = 0; i &lt; mDatabaseOfNames.size(); i++) { String dataNames = mDatabaseOfNames.get(i); if (dataNames.toLowerCase().startsWith(constraint.toString())) { FilteredArrayNames.add(dataNames); } } results.count = FilteredArrayNames.size(); results.values = FilteredArrayNames; Log.e("VALUES", results.values.toString()); return results; } }; return filter; } } </code></pre> <p>Inside <strong>perfromFiltering()</strong> you need to do actual comparison of the search query to values in your database. It will pass its result to <strong>publishResults()</strong> method.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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