preferenceScreens之间切换的Android [英] Android switching between PreferenceScreens
问题描述
我有一个preferencesScreen,也有一些preferences和子画面。它看起来是这样的:
I have a PreferencesScreen, that has some Preferences and a sub-screen. It looks like this:
<PreferenceScreen android:key="root">
<Preference android:key="first" />
<PreferenceScreen android:key="subScreen" />
<Preference android:key="second" />
<Preference android:key="third" />
</PreferenceScreen>
</PreferenceScreen>
当用户点击子屏幕,他被转移到子屏幕视图。现在我想将用户重定向到根preference屏幕,当他点击第二或第三。我似乎还没有找到合适的API要么接近的子屏幕,或专注于previous之一。想法?
When user clicks the subscreen, he is moved to the subscreen view. Now I want to redirect the user to "root" preference screen when he clicks on "second" or "third". I don't seem to find the right API to either close the subscreen, or focus the previous one. Ideas?
推荐答案
preference子屏幕显示为一个对话框,在你的情况下,将足以关闭该对话框重新presenting相应的 preferenceScreen
。将在的preferenceClick()
方法,下面的代码片断到在preferenceClickListener
你可能设置为第二和第三preferences关闭对话框:
Preference subscreen is displayed as a dialog, in your case it would be enough to dismiss the dialog representing appropriate PreferenceScreen
. Insert the following snippet into onPreferenceClick()
method of OnPreferenceClickListener
you probably set for "second" and "third" preferences to close the dialog:
PreferenceScreen ps = (PreferenceScreen)PrefsActivity.this.getPreferenceScreen()
.findPreference("subScreen");
ps.getDialog().dismiss();
其中, prefsActivity
是 preferenceActivity
的封闭实例是应用程序中使用。
where PrefsActivity
is the enclosing instance of PreferenceActivity
that is used in your application.
这篇关于preferenceScreens之间切换的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!