开发者

how to show progress dialog in oncreate in android app

In onCreate() of the activity, I'm force changing the orientation of the activity from portrait to landscape. This is working but there is a small delay of about a sec in the emulator. This activity is actually one开发者_运维问答 of the tabs. So when the user clicks on the tab he would expect an immediate response. So I want to show a progress dialog until the view is completely loaded. How do I achieve this? I tried to do the below but it doesn't work,

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.chart);

    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage("Loading...");
    dialog.show();

    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    .
    .
    .
    dialog.dismiss();//after the view is loaded completely   }

Any suggestion is appreciated.


Actually, I don't think your application is visiable yet .. not at the onCreate(). Check the eventing lifecycle ... onResume or maybe onStart ... where ever your Acitivity is actually visiable is where you should do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜