Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat goes wrong when filtering items from ListView in android?
    text
    copied!<p>I have a custom listView using BaseAdapter. In which phonebook contacts displays. In this listView two textbox displays name and numbers accordingly. Now I'm trying to add functionally on searchbox top of on the listView but I'm having some problem I don't know what when I see my logcat window in eclipse then I can see clearly the filtered list but the device listView is not changing any more. Please follow my code bellow: </p> <pre><code> package com.leaning.him; public class ForHimActivity extends Activity { private ListView contactList = null; private LayoutInflater mInflater; private String phoneNo; private String contact; private ContentResolver cr; private Cursor cursor; public ArrayList&lt;String&gt; aarr = new ArrayList&lt;String&gt;(); public ArrayList&lt;String&gt; aarr2 = new ArrayList&lt;String&gt;(); private static String ClickedNum; private static boolean check; private DBAdapter db; CustomkListAdapter adapter; EditText searchBar; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); searchBar = (EditText)findViewById(R.id.serchEditBox); aarr.clear(); aarr2.clear(); adapter = new CustomkListAdapter(ForHimActivity.this); contactList = (ListView)findViewById(R.id.facebookList); contactList.setAdapter(adapter); TextWatcher searchTextWatcher = new TextWatcher() { public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) { Log.v("","This is what you entred : "+s.toString()); adapter.getFilter().filter(s); adapter.notifyDataSetChanged(); contactList.setAdapter(adapter); } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub } public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } }; searchBar.addTextChangedListener(searchTextWatcher); } public class CustomkListAdapter extends BaseAdapter { ArrayList&lt;String&gt; arrayList; ArrayList&lt;String&gt; originallist; public CustomkListAdapter(Context context){ // Log.v("","This is context of BaseAdapter Class : "+context); mInflater = LayoutInflater.from(context); arrayList = new ArrayList&lt;String&gt;(); originallist = new ArrayList&lt;String&gt;(); originallist = aarr; cr = context.getContentResolver(); cursor = cr.query( ContactsContract.Contacts.CONTENT_URI, null, ContactsContract.Contacts.IN_VISIBLE_GROUP + "=1", null, null); db = new DBAdapter(context); } public int getCount() { return cursor.getCount(); // return 5; } public Object getItem(int position) { return aarr.get(position); } public long getItemId(int position) { return position; } public void getContacts(){ while(cursor.moveToNext()){ int nameFiledColumnIndex = cursor.getColumnIndex( ContactsContract.Contacts.DISPLAY_NAME); String id = cursor.getString( cursor.getColumnIndex(ContactsContract.Contacts._ID)); Cursor pCur = cr.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null); while (pCur.moveToNext()) { phoneNo = pCur.getString(pCur.getColumnIndex( ContactsContract.CommonDataKinds.Phone.NUMBER)); }//end inner while contact = cursor.getString(nameFiledColumnIndex); aarr.add(contact); aarr2.add(phoneNo); //Log.v("","Checkd this : "+aarr); } } public View getView(final int position, View convertView, ViewGroup parentView) { int i = 0; ViewHolder holder = null; if(convertView == null) { // Log.v("","position : "+position); }//end if else { holder = (ViewHolder) convertView.getTag(); }//end else holder = new ViewHolder(); convertView = mInflater.inflate(R.layout.twitter_row, null); holder.txtName = (TextView) convertView.findViewById(R.id.txtName); holder.txtnumber = (TextView) convertView.findViewById(R.id.txtnumber); holder.chkBox = (CheckBox) convertView.findViewById(R.id.chkAdd); if(cursor != null){ getContacts(); db.open(); Cursor c = db.getAllData(); if(c.moveToFirst()){ do { if(aarr2.get(position).replace("-", "").equals(c.getString(2))){ holder.chkBox.setChecked(true); } } while (c.moveToNext()); } db.close(); c.close(); }else { //Log.v("","Not Found any contacts...."); } holder.txtName.setText(aarr.get(position)); holder.txtnumber.setText(aarr2.get(position)); // Log.v("","Now heck : "+aarr.get(i)); i++; if(position == 1){ for(int j=0;j&lt;100;j++){ // // Log.v("","Contacts :"+aarr.get(i)); } } holder.chkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buton, boolean itemChked) { check = itemChked; ClickedNum = aarr2.get(position).replace("-", ""); if(check == true){ //Log.v("","This will save : "+ClickedNum.replace("-", "")); db.open(); db.insert(ClickedNum, check); db.close(); }else if (check == false){ db.open(); db.deleteFromNum(ClickedNum); db.close(); } } }); cursor.close(); // Log.v("","Latest getView() : "+aarr.get(position)); return convertView; } public class ViewHolder { public TextView txtName, txtnumber ; CheckBox chkBox; Button btn; } public Filter getFilter() { Filter filter = new Filter(){ @Override protected void publishResults(CharSequence constraint, FilterResults results) { Log.v("","from pubishResult()"); arrayList = (ArrayList&lt;String&gt;) results.values; Log.v("","This is array lsit from publishResults() : "+arrayList); notifyDataSetChanged(); } @Override protected FilterResults performFiltering(CharSequence constraint) { Log.v("","from performFiltering()"); FilterResults results = new FilterResults(); List&lt;String&gt; FilteredArrList = new ArrayList&lt;String&gt;(); if (originallist == null ) { originallist = new ArrayList&lt;String&gt;(arrayList); } if (constraint == null || constraint.length() == 0) { results.count = originallist.size(); results.values = originallist; } else{ constraint = constraint.toString(); for (int i = 0; i &lt; originallist.size(); i++) { String data = originallist.get(i); if (data.toLowerCase().startsWith(constraint.toString())) { FilteredArrList.add(data); } } results.count = FilteredArrList.size(); results.values = FilteredArrList; } Log.v("","This is result : "+results); return results; } }; Log.v("","This is filter : "+filter.toString()); return filter; } } </code></pre> <p>} </p> <p>Following is my log catwindow when i press "A" from edittex::</p> <pre><code>10-18 12:57:41.273: I/InputDispatcher(1483): Delivering touch to current input target: action: 1, channel '407b51d8 com.android.settings/com.android.settings.WirelessSettings (server)' 10-18 12:57:41.406: I/ActivityManager(1483): Starting: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.TetherSettings } from pid 6709 10-18 12:57:41.414: W/ActivityManager(1483): Trying to launch com.android.settings/.TetherSettings 10-18 12:57:41.429: I/ApplicationPackageManager(6709): cscCountry is not German : INU 10-18 12:57:41.445: I/webclipboard(6709): clipservice: android.sec.clipboard.ClipboardExManager@40571208 10-18 12:57:41.546: D/WML_SISO(6709): InitPasteboardJni 10-18 12:57:41.671: D/dalvikvm(6709): GC_CONCURRENT freed 109K, 45% free 3116K/5639K, external 647K/1031K, paused 3ms+4ms 10-18 12:57:41.695: I/ActivityManager(1483): Displayed com.android.settings/.TetherSettings: +282ms 10-18 12:57:41.921: E/StatusBarPolicy(1535): ecio: 31 10-18 12:57:41.921: E/StatusBarPolicy(1535): iconLevel: 4 10-18 12:57:42.187: I/InputReader(1483): dispatchTouch::touch event's action is 0 10-18 12:57:42.187: I/InputDispatcher(1483): Delivering touch to current input target: action: 0, channel '407cbfc0 com.android.settings/com.android.settings.TetherSettings (server)' 10-18 12:57:42.203: I/InputReader(1483): dispatchTouch::touch event's action is 1 10-18 12:57:42.203: I/InputDispatcher(1483): Delivering touch to current input target: action: 1, channel '407cbfc0 com.android.settings/com.android.settings.TetherSettings (server)' 10-18 12:57:42.335: D/Tethering(1483): Tethering usb0 10-18 12:57:42.335: D/Tethering(1483): [ActiveSync] internet sharing is NOT blocked </code></pre> <p>Please guide me where I make mistakes............I hope what I describe above is enough for understanding my problem.</p>
 

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