カスタムトーストを作成しようとしていますが、次のエラーが発生します。
シンボルが見つかりません(ViewGroup)findViewById(R.id.toast_root));
同時に、findViewById()
コードの他の行にも表示される可能性があります。私の間違いは何ですか?
public class MyCustomToast extends Toast {
public MyCustomToast(Context context){
super(context);
}
public static Toast customToast(Context context, CharSequence text, int duration) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_root));
ImageView image = (ImageView) layout.findViewById(R.id.toast_image);
image.setImageResource(R.drawable.skipper_toast);
TextView text_toast = (TextView) layout.findViewById(R.id.toast_text);
text_toast.setText(text);
Toast toast = new Toast(context);
toast.setGravity(Gravity.TOP, 0, 0);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
return toast;
}
}