在android中搜索结果后,Listview没有显示

时间:2014-09-23 09:22:00

标签: android listview

我正在研究android中的搜索功能。我能够完美地搜索结果。但是当我按退格键时,原始列表视图没有显示。你们可以告诉我任何解决方案。

 @Override
    public Filter getFilter() {


        Filter filter = new Filter(){

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {

                FilterResults results = new FilterResults();

                ArrayList<Details> FilteredArrList = new ArrayList<Details>();

                //ArrayList<Details> normalList = new ArrayList<Details>();

                if(mOriginalValues==null)
                {
                      mOriginalValues = new ArrayList<Details>(mDisplayedValues);

                }

                if(constraint==null || constraint.length()==0)
                {

                     results.values = mOriginalValues;
                     results.count = mOriginalValues.size();

                }

             else
                {
                    constraint = constraint.toString().toLowerCase();

                    for(int i=0;i<mOriginalValues.size();i++)
                    {
                        String data = mOriginalValues.get(i).getName();

                        if(data.toLowerCase().startsWith(constraint.toString()))
                        {
                            FilteredArrList.add(new Details(mOriginalValues.get(i).getImage(),mOriginalValues.get(i).getName())); 
                        }
                    }
                }

                results.count = FilteredArrList.size();
                results.values = FilteredArrList;

                // TODO Auto-generated method stub
                return results;
            }

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence constraint,
                    FilterResults results) {

                mDisplayedValues = (ArrayList<Details>)results.values;

                notifyDataSetChanged();

                if(mDisplayedValues == null)
                {

                    System.out.println("came here");
                }



            }

        };


        return filter;
    }

0 个答案:

没有答案