安卓:窗口管理$ BadTockenException上微调请点击 [英] Android :WindowManager$BadTockenException on Spinner Click

查看:156
本文介绍了安卓:窗口管理$ BadTockenException上微调请点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在home.class一个微调。当我点击微调,该过程停止显示异常窗口管理$ BadTockenException被抓住了。

I have a spinner in my home.class. When I click on the spinner, the process is stopped showing exception that WindowManager$BadTockenException is caught.

我打电话这个home.class从main.class延伸的ActivityGroup。

I am calling this home.class from main.class which extends ActivityGroup.

如果我仅仅只能运行home.class,微调是显示所有项目。但问题不仅是从main.class调用home.class。

If I am simply run only the home.class, the spinner is showing all items. But the problem is only with calling home.class from main.class.

下面是我的code。请告诉我这是为什么发生了。

The following are my code. Please tell me why this is happened.

public class main extends ActivityGroup
{
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
       Intent intent=new Intent(this,home.class);
       View view=getLocalActivityManager().startActivity("1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
       setContentView(view);
  }

}

String[] country={"Please selects","US","INDIA","UK"};
Spinner s2 = (Spinner) findViewById(R.id.spinnerCountry);
ArrayAdapter<CharSequence> adapterCountry=new ArrayAdapter(this,android.R.layout.simple_spinner_item,country);
adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapterCountry);

s2.setOnItemSelectedListener(new OnItemSelectedListener()
{
     public void onItemSelected( AdapterView<?> parent, View view, int position, long id)
     {
            countryName=country[position];
     }

      public void onNothingSelected(AdapterView<?> parent)
     {
            countryName=country[0];
      }

});

主题[&LT; 1>主](暂停(例外窗口管理$ BadTokenException))
    AlertDialog(对话).show()线:245
    AlertDialog $ Builder.show()线:802
    Spinner.performClick()线:260
    查看$ PerformClick.run()线:9080
    的ViewRoot(处理器).handleCallback(消息)线:587     的ViewRoot(处理器).dispatchMessage(消息)线:92     Looper.loop()线:123     ActivityThread.main(字符串[])线:3647
    Method.invokeNative(对象,对象[],上课,下课[],类,整型,布尔)行:不可用[本地方法]
    Method.invoke(对象,对象...)线路:507
    ZygoteInit $ MethodAndArgsCaller.run()线:839
    ZygoteInit.main(字符串[])线:597     NativeStart.main(字符串[])行:不可用[本地方法]

Thread [<1> main] (Suspended (exception WindowManager$BadTokenException))
AlertDialog(Dialog).show() line: 245
AlertDialog$Builder.show() line: 802
Spinner.performClick() line: 260
View$PerformClick.run() line: 9080
ViewRoot(Handler).handleCallback(Message) line: 587 ViewRoot(Handler).dispatchMessage(Message) line: 92 Looper.loop() line: 123 ActivityThread.main(String[]) line: 3647
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597 NativeStart.main(String[]) line: not available [native method]

感谢您......

推荐答案

该错误可能是您的home.class内给予的setContentView。

The error may be with the setContentView given inside your home.class.

而不是的setContentView的(yourlayout);

放弃,

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(yourlayout, null);
this.setContentView(viewToLoad);  
Spinner s2 = (Spinner) viewToLoad.findViewById(R.id.spinnerCountry);

和给你的微调code为:

And give your spinner code as:

ArrayAdapter<CharSequence> adapterCountry=new ArrayAdapter(this.getParent(),android.R.layout.simple_spinner_item,country);
adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapterCountry);

由于您使用的是活动组,你面对这个问题。希望这个解决方案可以帮助你。

Since you are using activity group, you face this issue. Hope this solution may help you.

这篇关于安卓:窗口管理$ BadTockenException上微调请点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆