开发者

how to set progress bar before spinner?

I have a alertdialog in which data coming from internet. Sometimes due to internet connectivity data comes late. so i want progress bar before spinner shows itself. while getting data i have written this.

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);

So how do i adjust progessDialog before alert dialog box?


You should load the data from the internet in a thread or an AsyncTask.

here you have a small article describing the possibilities.

I recommend the AsyncTask method, I post you a little pseudocode on how to do it, refer to the docs for more details on how you can pass the data you load in the doInBackground method to the onPostExecute for example.

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
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜