0

我希望我的列表视图按我创建的首选项中的选定选项排序,所以任何人都可以告诉我或提供一个代码来处理单选按钮的检查事件吗?
在此处输入图像描述

 <PreferenceCategory
   android:summary="Sorting Order"
   android:title="Sort By" >

  <ListPreference
 android:entries="@array/listOptions"
 android:entryValues="@array/listValues"
 android:key="listpref"
 android:summary="Sorting Values"
 android:title="Sort Order" />
 </PreferenceCategory>
4

1 回答 1

0

Within your activity, you would have it implement the SharedPreferences.OnSharedPreferenceChangeListener and implement the method:

onSharedPreferenceChanged(SharedPreferences prefs, String key) 

http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html

For example:

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        if (key != null) {
          if (key.contentsEquals("your_key_value_within_preferences") {
             //Stuff to do based on changes in preferences
          }
        }
}

Though it may differ from your application, check out the CubeLiveWallpaper example from the Google Android examples, as it has a thorough implementation.

于 2013-07-24T20:20:38.027 回答