【问题标题】:how to set progress bar before spinner?如何在微调器之前设置进度条?
【发布时间】:2011-01-26 06:50:13
【问题描述】:

我有一个警报对话框,其中的数据来自互联网。有时由于互联网连接数据来晚了。所以我想要在微调器显示之前进度条。在获取数据时我已经写了这个。

final String[] List= new String{ 'abc', 'def'};
                ArrayList<String> ListArray = new ArrayList<String>();  
                ListArray.addAll(Arrays.asList(List));
                ListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, ListArray);  
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Data");
                builder.setAdapter(ListAdapter, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        txtExec.setText(ClientList[item]);
                    } 
                });
                AlertDialog alert = builder.create();
                alert.show();


ProgressDialog dialog = new ProgressDialog(this);
                dialog.setMessage("Please wait while loading...");
                dialog.setIndeterminate(true);
                dialog.setCancelable(true);

那么如何在提示对话框之前调整progessDialog呢?

【问题讨论】:

    标签: android


    【解决方案1】:

    您应该在线程或 AsyncTask 中从 Internet 加载数据。

    here你有一篇描述可能性的小文章。

    我推荐AsyncTask 方法,我向您发布了一些伪代码,说明如何执行此操作,有关如何将doInBackground 方法中加载的数据传递给onPostExecute 的更多详细信息,请参阅文档例如。

    private class MyTask extends AsyncTask<Void, Void, Void> {
    
        protected void onPreExecute() {
            //setup and display the progressDialog
        }
    
        protected Void doInBackground(Void... params) {
            //do your data loading
            return null;
        }
    
        protected void onPostExecute(Void void) {
            //dismiss progress dialog and show the spinner
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      • 2012-06-07
      • 1970-01-01
      • 2020-06-25
      • 1970-01-01
      • 2014-10-05
      • 2012-02-04
      相关资源
      最近更新 更多