使用PreferenceActivity类,我想用EditTextPreference(EditTextPreference with android:key =“interval”)更新值,但输入的值没有考虑在内,输入值时出现此错误:
05-20 15:01:54.035 32516-32516/fr.lenours.sensortracker W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
05-20 15:01:54.036 32516-32516/fr.lenours.sensortracker W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
05-20 15:01:54.040 32516-32516/fr.lenours.sensortracker W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
05-20 15:01:54.040 32516-32516/fr.lenours.sensortracker W/IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
05-20 15:01:54.042 32516-32516/fr.lenours.sensortracker W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
这是PreferenceActivity类和他的.xml:
Settings.class:
public class Settings extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Graph">
<EditTextPreference
android:defaultValue="30000"
android:key="interval"
android:title="Interval (Seconds)" />
<fr.lenours.sensortracker.ConfirmationDialog
android:key="removeSteps"
android:summary="this action will remove the record"
android:title="delete all step recording" />
</PreferenceCategory>
<PreferenceCategory android:title="Map">
<fr.lenours.sensortracker.ConfirmationDialog
android:key="removeRoute"
android:summary="This action will delete map route"
android:title="Delete route" />
<fr.lenours.sensortracker.ConfirmationDialog
android:key="removeMarkers"
android:summary="this action will delete all markers on the map"
android:title="Delete markers" />
</PreferenceCategory>
<PreferenceCategory android:title="Tracker">
<EditTextPreference
android:key="stepObjective"
android:summary="Change your daily step objective"
android:title="Step daily objective" />
</PreferenceCategory>
</PreferenceScreen>
和 onSharedPreferenceChanged 方法:
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
switch (key) {
case "interval":
int interval = Integer.parseInt(sharedPreferences.getString("interval", "30000"));
stepGraphFrag.setInterval(interval * 1000); //second to microsecond
Log.d("main","Interval Changed ! Interval = " + interval);
stepGraphFrag.getHandler().removeCallbacks(stepGraphFrag.getUpdater());
stepGraphFrag.getHandler().postDelayed(stepGraphFrag.getUpdater(), 0);
break;
case "removeSteps":
if (sharedPreferences.getBoolean("removeSteps", true)) {
stepGraphFrag.resetGraph();
}
Log.d("main","Remove steps ! bool = " + sharedPreferences.getBoolean("removeSteps", true));
break;
case "removeRoute":
if (sharedPreferences.getBoolean("removeRoute", true)) {
osmFrag.resetRoute();
}
break;
}
}
如果你知道为什么我会收到这些警告,请提前感谢!