简体   繁体   English

无法在适配器类中绑定ImageView

[英]Can't bind ImageView in adapter class

I've got problem with binding ImageView in my adapter. 我在适配器中绑定ImageView时遇到问题。 How I should do it properly? 我应该怎么做呢?

Here's the code: 这是代码:

Override public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view != null) {
        holder = (ViewHolder) view.getTag();
    } else {
        view = LayoutInflater.from(getContext()).inflate(R.layout.weather_list_item, parent, false);
        holder = new ViewHolder(view);
        view.setTag(holder);
    }
    Weather model = getItem(position);
    holder.weatherIcon.setImageResource(utils.setWeatherIcon(model.getForecastID(), weatherIcon)); <- on the weatherIcon, I've got the "Cannot resolve symbol "weatherIcon"

static class ViewHolder {
    @BindView(R.id.hourly_temperature)
    TextView temperature;
    @BindView(R.id.hourly_airPressure)
    TextView airPressure;
    @BindView(R.id.hourly_airHumidity)
    TextView airHumidity;
    @BindView(R.id.hourly_windSpeed)
    TextView windSpeed;
    @BindView(R.id.hourly_time)
    TextView hour;

    @BindView(R.id.hourly_weatherIcon)
    ImageView weatherIcon;

    public ViewHolder(View view) {
        ButterKnife.bind(this, view);
    }
}

Before I used ButterKnife, I was declaring ImageView like that: 在使用ButterKnife之前,我是这样声明ImageView的:

    ImageView iv = view.findViewById(R.id.someID);
    utils.setWeatherIcon(model.getIconID(), iv);

and everything was runing just fine. 一切运行正常。

Instead of 代替

@BindView(R.id.hourly_weatherIcon) ImageView weatherIcon;

use 采用

@Bind(R.id.hourly_weatherIcon) ImageView weatherIcon;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JMockit-无法将模拟类绑定到测试类 - JMockit - Can't bind mocked class to tested class 我可以自动连接适配器类吗? - Can I Autowire an Adapter Class? 适配器内ImageView上的NullPointerException - NullPointerException on ImageView inside Adapter CustomList适配器不是TextView和ImageView - CustomList adapter not TextView and ImageView 为什么我不能将背景图像设置为从相关片段类声明到片段 xml 配置中的 ImageView? - Why I can't set a background image into an ImageView declared into a fragment xml configuration from the related fragment class? 在数据库适配器中无法完成从类到非静态方法的静态引用 - static reference from class to non-static method in data base adapter can't be done 为什么 Class 适配器设计模式不能使用一个接口代替多个 Inheritance? - Why the Class Adapter Design Pattern Can't Use an Interface Instead of Multiple Inheritance? 为什么我不能在AsyncTask中为另一个类的ListView设置适配器? - Why I can't set adapter in AsyncTask for ListView from another class? 第二个活动不会启动适配器类 - Second Activity Won't Start Adapter class 无法从其他类更改Imageview的图像 - Can not change the image of Imageview from another class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM