【问题标题】:How to solve android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager如何解决 android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager
【发布时间】:2014-08-15 01:54:48
【问题描述】:

我使用 ViewPager LocalActivityManager 加载 Activity。当我想在该 Activity 中显示 Dialog 时。错误显示;似乎对话框中使用的上下文不适用,如何获取正确的上下文;

vp = (MyViewPager) recommendView.findViewById(R.id.vp);
views = new ArrayList<View>();
Intent i1 = new Intent(this, Activity1.class);
Intent i2 = new Intent(this, Activity2.class);
Intent i3 = new Intent(this, Activity3.class);
Intent i4 = new Intent(this, Activity4.class);
Intent i5 = new Intent(this, Activity5.class);
Intent i6 = new Intent(this, Activity6.class);
Intent i7 = new Intent(this, Activity7.class);
views.add(getView("1", i1));
views.add(getView("2", i2));
views.add(getView("3", i3));
views.add(getView("4", i4));
views.add(getView("5", i5));
views.add(getView("6", i6));
views.add(getView("7", i7));
adapter = new MyPageAdapter(views);
vp.setAdapter(adapter);

//getView Code

private View getView(String id, Intent intent) {
    return manager.startActivity(id, intent).getDecorView();
}
//show dialog Code

bt2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog dialog=new Dialog(Activity7.this);
            dialog.setTitle("title");
            dialog.show();
        }
});

【问题讨论】:

    标签: android android-activity dialog android-viewpager


    【解决方案1】:

    我不知道你写对了吗? 但从问题来看,我认为您可以尝试: 在里面的activity中定义接口,例子;

    public interface DealDialog{
       public interface showDialog();
    }
    

    然后,在外部(TabHost)实现这个接口。

    你可以试试。

    对不起,我的英语太差了,对不起。不明白的时候可以问我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-26
      • 2017-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-10
      相关资源
      最近更新 更多