2017-11-10 96 views
0

它显示相同的错误,但我尝试实现此功能。我不明白是什么造成问题,因为它只是班级中的另一个功能。 我正在实施这个使用SearchView和RecyclerAdapter。我已经看过其他代码,但都是以相同类型实现的。 这是full code无法解析方法getFilter()方法

class ProductsRecyclerAdapter extends RecyclerView.Adapter<ProductsRecyclerAdapter.MyViewHolder> implements Filterable { 

    List<ProductEntity> productList = Collections.emptyList(); 
    Context context; 
    List<ProductEntity> filteredProductList = Collections.emptyList(); 

    public ProductsRecyclerAdapter(List<ProductEntity> productList, Context context) { 
     this.productList = productList; 
     this.context = context; 
     filteredProductList = productList; 
    } 

    public class MyViewHolder extends RecyclerView.ViewHolder { 

     TextView product_name; 
     ImageView product_image; 
     CardView product_catalog_card; 
     AVLoadingIndicatorView progress_ball_image ; 

     public MyViewHolder(View view) { 
      super(view); 
      product_name = view.findViewById(R.id.product_name); 
      product_image = view.findViewById(R.id.product_image); 
      product_catalog_card = view.findViewById(R.id.product_catalog_card); 
      progress_ball_image = view.findViewById(R.id.progress_ball_image) ; 
     } 
    } 

    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_entity_design, parent, false); 
     return new MyViewHolder(itemView); 
    } 

    @Override 
    public void onBindViewHolder(final MyViewHolder holder, final int position) { 
     holder.product_name.setText(productList.get(position).about); 
     holder.progress_ball_image.setVisibility(View.VISIBLE) ; 
     Picasso.with(context) 
       .load(productList.get(position).image.get(0).url) 
       .centerInside() 
       .resize(200, 200) 
       .memoryPolicy(MemoryPolicy.NO_STORE) 
       .into(holder.product_image, new Callback() { 
        @Override 
        public void onSuccess() { 
         holder.progress_ball_image.smoothToHide(); ; 
        } 

        @Override 
        public void onError() { 

        } 
       }); 
     holder.product_catalog_card.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(v.getContext(), ProductDetail.class); 
       intent.putExtra("product", productList.get(position)); 
       v.getContext().startActivity(intent); 
      } 
     }); 
    } 

    @Override 
    public int getItemCount() { 
     return productList.size(); 
    } 

    @Override 
    public Filter getFilter() { 
     return new Filter() { 
      @Override 
      protected FilterResults performFiltering(CharSequence charSequence) { 
       String charString = charSequence.toString(); 
       if (charString.isEmpty()) { 
        filteredProductList = productList; 
       } else { 
        ArrayList<ProductEntity> filteredList = new ArrayList<>(); 
        for (ProductEntity productEntity : productList) { 
         if (productEntity.about.toLowerCase().contains(charString)) { 
          filteredList.add(productEntity); 
         } 
        } 
        filteredProductList = filteredList; 
       } 

       FilterResults filterResults = new FilterResults(); 
       filterResults.values = filteredProductList; 
       return filterResults; 
      } 

      @Override 
      protected void publishResults(CharSequence charSequence, FilterResults filterResults) { 
       filteredProductList = (ArrayList<ProductEntity>) filterResults.values; 
       notifyDataSetChanged(); 
      } 
     }; 
    } 
} 

This is the error snapshot

+0

我可以看到您的ProductsRecyclerAdapter类具有包可见性。你是否试图在同一个包中使用这个适配器? – Kulebin

+0

是的,这是否构成任何问题。如果您想查看,我已将上述链接发布在上述链接中。我刚刚通过创建另一个类来检查它,但这没有帮助。 –

回答

1

拉胡尔·米什拉,你看,你宣布你的变量作为RecyclerView.Adapter但你需要ProductsRecyclerAdapter。更改变量的类型,它将起作用

+0

这样一个愚蠢的错误。我几个小时就沉迷于它。非常感谢你的帮助。 –