Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used an <code>EditText</code> to do the job.</p> <p>First I created two copies of the array to hold the list of data to search:</p> <pre><code>List&lt;Map&lt;String,String&gt;&gt; vehicleinfo; List&lt;Map&lt;String,String&gt;&gt; vehicleinfodisplay; </code></pre> <p>Once I've got my list data from somewhere, I copy it:</p> <pre><code>for(Map&lt;String,String&gt;map : vehicleinfo) { vehicleinfodisplay.add(map); } </code></pre> <p>and use a <code>SimpleAdapter</code> to display the display (copied) version of my data:</p> <pre><code>String[] from={"vehicle","dateon","dateoff","reg"}; int[] to={R.id.vehicle,R.id.vehicledateon,R.id.vehicledateoff,R.id.vehiclereg}; listadapter=new SimpleAdapter(c,vehicleinfodisplay,R.layout.vehiclelistrow,from,to); vehiclelist.setAdapter(listadapter); </code></pre> <p>Then I added a <code>TextWatcher</code> to the <code>EditText</code> which responds to an <code>afterTextChanged</code> event by clearing the display version of the list and then adding back only the items from the other list that meet the search criteria (in this case the "reg" field contains the search string). Once the display list is populated with the filtered list, I just call <code>notifyDataSetChanged</code> on the list's <code>SimpleAdapter</code>.</p> <pre><code>searchbox.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { vehicleinfodisplay.clear(); String search=s.toString(); for(Map&lt;String,String&gt;map : vehicleinfo) { if(map.get("reg").toLowerCase().contains(search.toLowerCase())) vehicleinfodisplay.add(map); listadapter.notifyDataSetChanged(); } }; ... other overridden methods can go here ... }); </code></pre> <p>Hope this is helpful to someone.</p>
    singulars
    1. This table or related slice is empty.
    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. 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