2011-08-22 100 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); 
}