Reputation: 11
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);
}
when i click on any button to call for show_popup it work fine but when i want show_popup() call onCreate() it not work. i got an error show on logcat like this
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)
please help me in advance thank you!
Upvotes: 1
Views: 801
Reputation: 37729
Use a Handler
object to show popup.
Handler hand = new Handler()
{
@Override
public void handleMessage(Message msg)
{
show_popup();
}
};
and call handler in onCreate()
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.question_layout);
hand.sendEmptyMessage(0);
}
Upvotes: 2