2017-11-10 142 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

這樣一個愚蠢的錯誤。我幾個小時就沉迷於它。非常感謝你的幫助。 –