0

I am getting this error while doing search functionality with custom listview in android.

@Override
protected void publishResults(CharSequence constraint,
    FilterResults results) {
        mList = (ArrayList<Details>) results.values;
        DetailsAdapter.this.notifyDataSetChanged();

        });
prakash
  • 1,413
  • 1
  • 21
  • 33
Prathyusha
  • 169
  • 2
  • 10
  • Looks like results.values contains String which you are casting to ArrayList
    ..
    – Petr Chudanic Sep 20 '14 at 07:57
  • try this => ` mList = (ArrayList
    ) results;`
    – Ved Sep 20 '14 at 09:01
  • @ved when i am trying to do that I am getting this compilation error. "Cannot cast from Filter.FilterResults to ArrayList
    "
    – Prathyusha Sep 22 '14 at 06:08
  • You are not adding data in mList in proper way.You need to get results.value in separate object then try to add that object values according to your Details class in Details onject then add this Detail object in Arraylist. – Ved Sep 22 '14 at 08:18
  • @ved yes you are right. I followed this tutorial http://stackoverflow.com/questions/14118309/how-to-use-search-functionality-in-custom-list-view-in-android . I am able filter the values. but when I backspace the results I am not getting normal list in my listview – Prathyusha Sep 22 '14 at 12:31
  • I didn't understand what are you trying to achieve? – Ved Sep 22 '14 at 12:36
  • @ved MyListview is not updating after filtering , when backspace key entered.. – Prathyusha Sep 22 '14 at 12:48
  • When you press backspace your adapter should get updated with the default list view for that you need to define a global arrayList and set initilize your adapter inside onCreate method like this. SearchAdapter searchAdapter = new SearchAdapter(this); searchList.setAdapter(searchAdapter);//ListView Now when you receive data in onQueryTextChanged method like this ArrayList arrayListDataDetails = (ArrayList) response; notify the adapater for the new dataset change like below searchAdapter.notifyDataSetChanged(); Hope this helps!! – Saurabh Sep 22 '14 at 13:27
  • @John I tried it.But not working out. :( – Prathyusha Sep 22 '14 at 13:31
  • Follow these two example one has source code download buttonhttp://karanbalkar.com/2014/03/tutorial-79-implement-listview-with-search-functionality-in-android/ and http://www.androidbegin.com/tutorial/android-search-listview-using-filter/ There should not be any problem in implementing it.. – Saurabh Sep 22 '14 at 13:43

1 Answers1

0

Here is my example of ListView may be it helps :

adapter=new ArrayAdapter<String>(ModifyList.this, android.R.layout.simple_list_item_1,list);
     lv.setAdapter( adapter);
     a=adapter;
     lv.setTextFilterEnabled(true);
     search_et.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {              
                ModifyList.this.a.getFilter().filter(cs);

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub

        }
    });
Ved
  • 1,035
  • 14
  • 28
  • Sorry to interrupt you. When my constraint values are null this action if(constraint==null || constraint.length()==0) { synchronized(this) { results.values = mOriginalValues; results.count = mOriginalValues.size(); } } is not performing. – Prathyusha Sep 22 '14 at 13:26