如何从首选项屏幕打开 AlertDialog?
我的活动低于
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
public class locationserviceSettings extends PreferenceActivity implements OnPreferenceChangeListener,OnSharedPreferenceChangeListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.locationservice);
// PreferenceManager.setDefaultValues(notificationSettings.this, R.xml.notification, true);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
System.out.println("Preference changed " + newValue);
return false;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
System.out.println("Shared preference changed" + key);
}
}
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Location service settings">
<CheckBoxPreference android:title="Location service"
android:key="locationService" android:defaultValue="true"
android:summary="checked for start location service in background"></CheckBoxPreference>
</PreferenceCategory>
<EditTextPreference android:title="Minimum time seconds"
android:key="time" android:dependency="locationService"
android:summary="Miminum time in seocnds for update location"></EditTextPreference>
<EditTextPreference android:title="Minimum distance meters"
android:key="distance" android:dependency="locationService"
android:summary="Miminum distance in meters for update location"></EditTextPreference>
</PreferenceScreen>
当我检查 checkPreference 时这两种方法都没有打印任何内容
My activity is below
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
public class locationserviceSettings extends PreferenceActivity implements OnPreferenceChangeListener,OnSharedPreferenceChangeListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.locationservice);
// PreferenceManager.setDefaultValues(notificationSettings.this, R.xml.notification, true);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
System.out.println("Preference changed " + newValue);
return false;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// TODO Auto-generated method stub
System.out.println("Shared preference changed" + key);
}
}
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Location service settings">
<CheckBoxPreference android:title="Location service"
android:key="locationService" android:defaultValue="true"
android:summary="checked for start location service in background"></CheckBoxPreference>
</PreferenceCategory>
<EditTextPreference android:title="Minimum time seconds"
android:key="time" android:dependency="locationService"
android:summary="Miminum time in seocnds for update location"></EditTextPreference>
<EditTextPreference android:title="Minimum distance meters"
android:key="distance" android:dependency="locationService"
android:summary="Miminum distance in meters for update location"></EditTextPreference>
</PreferenceScreen>
both of these method are not printing anything when i chacked the checkPreference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 <代码>onPreferenceStartFragment()。它成为已弃用的
onPreferenceTreeClick
() 的替代品。use
onPreferenceStartFragment()
. It became a replacement for deprecatedonPreferenceTreeClick
().像这样注册你的监听器(例如在 onCreate() 中):
Register your listener (for example in onCreate()) like this: