私は初心者で、いくつかのアクティビティを持つ単純な Android アプリを作成しています。各アクティビティでは、進行状況ダイアログとカスタム レイアウトのトーストを使用する必要があります。また、いくつかの環境設定を保存してロードする必要があります。これらすべてのメソッドを別のクラスに配置するにはどうすればよいですか。すべてのアクティビティで同じコードを記述したくありません。静的クラスにすることはできますか?
ありがとうございました。
private void createCustomToast(String msg, String status) {
Context context = getApplicationContext();
LayoutInflater inflater = getLayoutInflater();
View toastRoot = inflater
.inflate(R.layout.custom_toast_two_lines, null);
TextView text = (TextView) toastRoot.findViewById(R.id.toastText);
TextView textTriageStatus = (TextView) toastRoot
.findViewById(R.id.status);
textTriageStatus.setText(status);
text.setTextColor(Color.BLACK);
text.setText(msg);
Toast toast = new Toast(context);
toast.setView(toastRoot);
toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 0);
toast.show();
}
private void savePreferences(String key, int value) {
SharedPreferences sharedPreferences = getSharedPreferences(
"APP_PREFERENCES", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(key, value);
editor.commit();
}
private String loadPreferences(String key) {
SharedPreferences sharedPreferences = getSharedPreferences(
"APP_PREFERENCES", MODE_PRIVATE);
String strSavedMem1 = sharedPreferences.getString(key, "");
return strSavedMem1;
}