我创建了一个 PreferenceActivity,它有一个 ListPreference(prefViewPos) 和一个 Preference(prefAlert)。当用户单击“prefAlert”时,会打开一个确定取消对话框。现在,当屏幕旋转时,我的警报对话框将关闭,但如果“prefViewPos”对话框打开,则它不会关闭。那么为什么我的警报对话框会在屏幕旋转时关闭 ListPreference 对话框时关闭?
代码:
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.setting);
getListView().setBackgroundResource(R.drawable.background);
getListView().setCacheColorHint(Color.TRANSPARENT);
prefViewPos = (ListPreference)findPreference(NetworkMonitorApp.PREF_VIEW_POS);
if(prefViewPos != null)
{
String viewPosEntries[] = {"Top Left","Top Center","Top Right"};
String viewPosEntryValues[] = {String.valueOf(0),String.valueOf(1),String.valueOf(2)};
prefViewPos.setEntries(viewPosEntries);
prefViewPos.setEntryValues(viewPosEntryValues);
if(prefViewPos != null)
{
prefViewPos.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
{
@Override
public boolean onPreferenceChange(Preference arg0, Object arg1)
{
//Some code here
return true;
}
});
}
}
prefAlert = (Preference)findPreference("PrefAlert");
if(prefAlert != null)
{
prefTextColor.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference preference)
{
//Open dialog by AlertDialog.Builder.show()
return true;
}
});
}