Android listfilter没有得到结果

时间:2013-07-23 09:17:36

标签: android listview filter

我正在使用listview过滤器,我正在使用输入类型文本检查文本,但listview适配器没有更新,我在Arraylist&中有文本值。我正在检查数据中的文本,其中数据包含完整的arraylist。 str是我从arraylist中分离出文本的字符串。

以下是代码:

 @Override
         public Filter getFilter() {
             Filter filter = new Filter() {

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


                     data = arraylistmenu;
                     notifyDataSetChanged();  
                 }

                 @Override
                 protected FilterResults performFiltering(CharSequence constraint) {

                     FilterResults results = new FilterResults();        

                 arraylistmenu = new ArrayList<HashMap<String,Object>>();


                     if (arraylist == null) {
                         arraylist = new HashMap<String, Object>(); // saves the original data in mOriginalValues
                         arraylist.put("text", str);
                     }


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

                         // set the Original result to return  
                         results.count = arraylist.size();

                         results.values = arraylist;


                     } else {

                         constraint = constraint.toString().toLowerCase();
                        HashMap<String, Object> filterableString;
                         for (int i = 0; i < arraylist.size(); i++) {
                             filterableString = new HashMap<String, Object>();



                             filterableString.put("text", arraylist.get(i));

                             System.out.println("filterableString="+filterableString);

                             if (filterableString.toString().startsWith(constraint.toString())) {
                                 arraylistmenu.add(filterableString);
                             }
                         }

                         results.count = arraylistmenu.size();
                         results.values = arraylistmenu;
                     }
                     return results;
                 }
             };
             return filter;
         }
    }

有人可以帮助我@Thanks

0 个答案:

没有答案