2011-08-22 65 views
1
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

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

和呼叫处理程序(在代码的方法的名称是show_popup(),在logcat的是show_pupup()。这是一个错误吗?请发布完整的异常logcat,而不仅仅是三条随机线 – Egor

回答

2

使用一个Handler对象来显示弹出。中的onCreate)

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