TabActivity 与 ActivityGroup 和 PreferenceActivity 子级
我有一个 TabActivity,其中每个选项卡都有 ActivityGroup。 在第一组的主 ActivityChild 上,我有一个菜单选项,它为用户提供了打开首选项的选项。 当我单击菜单上的“首选项”时,我会在 ActivityGroup 内启动 PreferenceActivity,这会在第一个选项卡上显示 PreferenceActivity。 问题是当我单击任何必须显示对话框(用于 EditTextPreference)的特定首选项时。 我有以下例外:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@405d3a20
我知道问题是因为 PreferenceActivity 显示的对话框使用了错误的上下文,但我现在不知道如何更改创建的对话框的上下文。
下面是我创建的 PreferenceActivity。
public class PreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preferences);
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
}
}
我不想创建自定义对话框。我想为此使用 PreferenceActivity 机制。 下面是我用来添加到组的代码:
i = new Intent(MyActivity.this, PreferencesActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("PreferencesActivity", i);
有什么想法吗?
I have a TabActivity where each tab has ActivityGroup.
On the home ActivityChild of the first group I have an menu option, which gives to the user the option to open preferences.
When I click "Preferences" on menu, I start PreferenceActivity inside ActivityGroup, which shows PreferenceActivity on the first tab.
The problem is when I click on any specific preference which has to show a Dialog (for EditTextPreference).
I have the following exception:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@405d3a20
I understand that the problem is because Dialog to be shown by PreferenceActivity uses wrong context, BUT i don't now how change the context of created dialog.
Belows is the PreferenceActivity I've created.
public class PreferencesActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preferences);
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key) {
}
}
I don't want to create custom dialogs. I want to use the mechanism of PreferenceActivity for that.
Below is the code that I'm using to add to group:
i = new Intent(MyActivity.this, PreferencesActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("PreferencesActivity", i);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)