问题描述
我有一个TabActivity其中每个标签都有的ActivityGroup。在第一组的归属ActivityChild我有一个菜单选项,这给用户以打开preferences的选项。当我点击菜单preferences,我开始里面的ActivityGroup preferenceActivity,其中显示了第一个选项卡上的preferenceActivity。问题是,当我点击任何特定的preference有显示一个对话框(为的EditText preference)。我有以下异常:
android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.app.LocalActivityManager$LocalActivityRecord@405d3a20
据我所知,这个问题是因为对话框由preferenceActivity显示使用了错误的情况下,但我不现在如何改变创造对话的环境。
初级讲座是我创建了preferenceActivity。
公共类preferencesActivity扩展preferenceActivity实现OnShared preferenceChangeListener {
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout preferences);
加preferencesFromResource(R.xml preferences。);
共享preferences preFS = preferenceManager.getDefaultShared preferences(getApplicationContext());
prefs.registerOnShared preferenceChangeListener(本);
}
@覆盖
公共无效onShared preferenceChanged(共享preferences共享preferences,字符串键){
}
}
我不希望创建自定义对话框。我想用preferenceActivity的机制这一点。下面是我使用添加到组中的code:
I =新的意图(MyActivity.this,preferencesActivity.class);
TabGroupActivity parentActivity =(TabGroupActivity)的getParent();
parentActivity.startChildActivity(preferencesActivity,我);
任何想法?
这是非常普遍的问题对话框的选项卡中的主机。
其实活动范围内不足以显示一个对话框,在选项卡。
你必须使用你的GroupActivity进行对话的范围内加以无一例外启用
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?
This is very common problem with dialog's in Tab Host.
Actually the Activity context is not sufficient to show a Dialog in Tab.
You have to use the context of your GroupActivity for the dialog to be enabled without exception
这篇关于TabActivity用的ActivityGroup和preferenceActivity孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!