我希望能夠調用Utills類的方法在屏幕上彈出自定義Toast消息。Utills類的自定義Toast
我的代碼:
static public void ShowToast(Context context,String message, int duration)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Inflate the Layout
View layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.custom_toast_layout));
TextView text = (TextView) layout.findViewById(R.id.textToShow);
// Set the Text to show in TextView
text.setText(message);
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(duration);
toast.setView(layout);
toast.show();
}
我有4行,其中i調用
(ViewGroup) findViewById(R.id.custom_toast_layout)
我有其中規定一個編譯錯誤一個proble:
方法findViewById(INT )未定義爲類型SystemUtills
我該如何解決這個問題?
謝謝。
參考http://developer.android.com/guide/topics/ui/notifiers/toasts.html#CustomToastView%20。 –