我正试图使用setImageResource(R.drawable.etape_too(从片段中更改ImageView的图像;但是应用程序在没有任何日志的情况下崩溃。
你知道吗?
非常感谢最大
public class PlateauJeu extends Fragment {
public static ImageView EtatEtape1;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.plateau_layout, container, false);
ImageView etatEtape1 = (ImageView) view.findViewById(R.id.imageViewEtape1);
PlateauJeu.EtatEtape1.setImageResource(R.drawable.etape_passed);
return view;
}
public static void nouvelleEtape(Context context){
EtatEtape1.setImageResource(R.drawable.etape_todo);
}
}
View view = inflater.inflate(R.layout.plateau_layout, container, false);
ImageView etatEtape1 = (ImageView) view.findViewById(R.id.imageViewEtape1);
PlateauJeu.EtatEtape1.setImageResource(R.drawable.etape_passed);
小心!您正在未初始化的组件中设置图像。我想你想这么做:
View view = inflater.inflate(R.layout.plateau_layout, container, false);
EtatEtape1 = (ImageView) view.findViewById(R.id.imageViewEtape1);
EtatEtape1.setImageResource(R.drawable.etape_passed);