Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>edit=(EditText)findViewById(R.id.editText1); edit.addTextChangedListener(filterTextWatcher); private TextWatcher filterTextWatcher =new TextWatcher() { public void afterTextChanged(Editable s) { mlist.getFilter().filter(edit.getText().toString()); } public void beforeTextChanged(CharSequence s, int start, int count,int after) { } public void onTextChanged(CharSequence s, int start, int before,int count) { } }; public class CustomAdapter extends ArrayAdapter&lt;Employee&gt; { private ImageButton img; private ArrayList&lt;Employee&gt; items; private ArrayList&lt;Employee&gt; dupItems; public ArrayList&lt;Employee&gt; filtered; private Activity currActivity; public Employee emp; private EmpService empSer; private Filter filter; public CustomAdapter(Activity context, int textViewResourceId, ArrayList&lt;Employee&gt; empList) { super(context, textViewResourceId, empList); currActivity = context; this.filtered=empList; this.items = filtered; setNotifyOnChange(true); empSer = new EmpService(); emp=new Employee(); } public int getCount() { return items.size(); } public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater vi = (LayoutInflater) currActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = vi.inflate(R.layout.result, null); } emp = items.get(position); view.setId(emp.empId); if (emp != null) { TextView id = (TextView) view.findViewById(R.id.textView1); TextView name = (TextView) view.findViewById(R.id.textView2); TextView com = (TextView) view.findViewById(R.id.textView3); TextView joindate = (TextView) view.findViewById(R.id.textView4); img = (ImageButton) view.findViewById(R.id.imageButton1); if (id != null) { id.setText(" "+emp.empId); } if(name != null){ name.setText(" "+emp.empName); } if(com != null){ com.setText(" "+emp.company); } if(joindate != null){ joindate.setText(" "+emp.joinDate); } return view; } public void notifyDataSetInvalidated() { super.notifyDataSetInvalidated(); } @Override public Filter getFilter() { if(filter == null) filter = new MangaNameFilter(); return filter; } private class MangaNameFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence constraint) { // NOTE: this function is *always* called from a background thread, and // not the UI thread. constraint = edit.getText().toString().toLowerCase(); FilterResults result = new FilterResults(); if(constraint != null &amp;&amp; constraint.toString().length() &gt; 0) { empList=empSer.GetAllDetails(); items=empList; ArrayList&lt;Employee&gt; filt = new ArrayList&lt;Employee&gt;(); ArrayList&lt;Employee&gt; lItems = new ArrayList&lt;Employee&gt;(); synchronized(this) { lItems.addAll(items); } for(int i = 0, l = lItems.size(); i &lt; l; i++) { Employee m = lItems.get(i); if(m.empName.toLowerCase().contains(constraint)||m.joinDate.toLowerCase().contains(constraint)|| m.company.contains(constraint)) filt.add(m); } result.count = filt.size(); result.values = filt; } else { empList=empSer.GetAllDetails(); items=empList; synchronized(this) { result.count = items.size(); result.values = items; } } return result; } @SuppressWarnings("unchecked") @Override protected void publishResults(CharSequence constraint, FilterResults result) { // NOTE: this function is *always* called from the UI thread. filtered = (ArrayList&lt;Employee&gt;)result.values; mlist=new CustomAdapter(currActivity, R.layout.result, filtered); list.setAdapter(mlist); } } </code></pre>
 

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