このアクティビティでは、showCustomAlert
メソッドがあります。このメソッドは、別のアクティビティを呼び出す必要があります。コンテキストレイアウトインフレータをandroidの別のアクティビティに呼び出す方法
public void showCustomAlert(Context context , int message) {
try {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout));
TextView text = (TextView) layout.findViewById(R.id.textToShow);
text.setText(message);
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
} catch (Exception e) {
e.getMessage();
}
}
これは私がshowCustomAlertメソッドを呼び出す別のアクティビティです。エラーnullポインタ例外が発生しています。
Toss toast = new Toss();
toast.showCustomAlert(this , R.string.error_toast);
ポストフル* Logcatをするのに役立ちます。 –
ポストスタックタール – FAT
custom_toastとcustom_toast_layout XMLを投稿できますか? – FAT