0

私の Android アプリではSharedPreferences、ユーザーがいくつかの設定を管理できるようにしています。ユーザーが設定を変更し、設定ページからアプリに戻った後、ビュー (フラグメント) で SharedPreferences の最新の値を使用する必要があります。

変更には、配色を使用するためのカスタム ビューの再読み込みや、リスト ビューのフィルタリングの削除が含まれる場合があります。

現在、アプリを再起動したときにのみ、必要な変更が適用されます。私の問題を解決する方法があると確信していますが、それを理解することができません。

私が Android 2.2 以降をサポートしていると仮定すると、サポート ライブラリ内に存在しない限り、このための新しい API は使用されない可能性があります。

4

2 に答える 2

1

Not exactly sure what your question is but it seems to me that when your user changes a setting and then hits the back button to return to the fragment you are not seeing the changes? if this is the case it is because when the user goes back android reinstates the version of the fragment that was on the stack (the one before any changes were made). My suggestion would be to try moving the loading of the new shared prefs to the onResume method for the fragment. This way they should be loaded when the user goes back.

Try this

@Override
public void onResume(){
super.onResume();
setContentView(R.layout.currentFrag); 

}

this should reload the page with the correct changes.

于 2013-08-07T11:33:54.390 に答える
0

現在のアクティビティがフォーカスを失ったかどうかを確認するには、onWindowFocusChanged メソッドを使用する必要があります。

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    // Add the code to perform on the fragments after the settings have changed.
}
于 2013-08-07T13:21:47.067 に答える