小编beb*_*ech的帖子

ProgressDialog直到函数完成后才显示

我正在尝试在加载一些数据时显示旋转进度,但直到数据加载后才显示?

以下是我尝试这样做的方法:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen1);

    //Show spinner while data is being loaded
    ProgressDialog dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);

    LoadPreferences();
    LoadData();

    //Remove the spinner once all the data has been loaded
    dialog.dismiss();
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

更新的代码:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.screen1);

//Show spinner while data is being loaded
final ProgressDialog dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);

// define and run background thread
Thread backgroundThread = new Thread(new Runnable() 
{            
    public void …
Run Code Online (Sandbox Code Playgroud)

android

1
推荐指数
1
解决办法
7523
查看次数

标签 统计

android ×1