How to get a context in a recycler view adapter

后端 未结 12 1436
一向
一向 2020-12-02 06:12

I\'m trying to use picasso library to be able to load url to imageView, but I\'m not able to get the context to use the picasso library correctly.



        
12条回答
  •  猫巷女王i
    2020-12-02 06:56

    If you are using Databinding on layout you can get the context from holder. An exemple below.

    @Override
    public void onBindViewHolder(@NonNull GenericViewHolder holder, int position) {
        View currentView = holder.binding.getRoot().findViewById(R.id.cycle_count_manage_location_line_layout);// id of your root layout
        currentView.setBackgroundColor(ContextCompat.getColor(holder.binding.getRoot().getContext(), R.color.light_green));
    }
    

提交回复
热议问题