我无法绑定或访问片段上的图像视图

时间:2017-11-03 05:29:28

标签: java android

我需要将Picasso与ImageView一起使用。我无法绑定或访问片段上的图像视图,它返回冗余。请帮助谢谢

enter image description here

2 个答案:

答案 0 :(得分:2)

找到解决方案

高于或等于API 26 以后无需投射任何视图

Imageview img = rootView.findViewById(R.id.imgView);

如果您使用以下API 26 ,则应投射视图

Imageview img = (ImageView)rootView.findViewById(R.id.imgView);

欲了解更多信息,请查看以下链接

No need to cast the result of findViewById?

答案 1 :(得分:0)

从API 26开始, findViewById 会对其返回类型使用推断,因此您不再需要进行强制转换。

<T extends View> T findViewById(int id)

API 级别26的旧签名

public View findViewById(int id){

}

API 级别26

开始的新签名
public <T extends View > T findViewById(int id){

}
  

冗余意味着额外或不必要   它只是warning而且它表示无需投射

试试这个

Imageview img = rootView.findViewById(R.id.imgView);