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)
请提前帮助我,谢谢!
答案 0 :(得分:2)
使用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);
}