gpt4 book ai didi

android - Activity 首次启动时无法开始创建弹出窗口

转载 作者:行者123 更新时间:2023-11-29 22:21:11 25 4
gpt4 key购买 nike

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.question_layout);
show_popup();
}

private void show_popup(){
LayoutInflater lf = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View m_view = lf.inflate(R.layout.popup_question, null);
m_popup_window = new PopupWindow(m_view,500,150,false);
m_popup_window.showAtLocation(m_full_page, Gravity.CENTER, 0, 0);
}

当我点击任何按钮调用 show_popup 时它工作正常但是当我想要 show_popup() 调用 onCreate() 时它不起作用。我在 logcat 上得到这样的错误显示

08-22 13:57:36.682: ERROR/AndroidRuntime(21860):     at tesingimage.com.testingimagemain.show_pupup(testingimagemain.java:41)
08-22 13:57:36.682: ERROR/AndroidRuntime(21860): at tesingimage.com.testingimagemain.onCreate(testingimagemain.java:23)
08-22 13:57:36.682: ERROR/AndroidRuntime(21860): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

请提前帮助我谢谢!

最佳答案

使用Handler 对象显示弹出窗口。

Handler hand = new Handler()
{
@Override
public void handleMessage(Message msg)
{
show_popup();

}
};

并在 onCreate() 中调用处理器

protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.question_layout);
hand.sendEmptyMessage(0);
}

关于android - Activity 首次启动时无法开始创建弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7144139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com