开发者

Can I restrict a ViewFlipper from flipping until an AsyncTask has been performed?

My application has a 开发者_JAVA技巧ViewFlipper with 3 ViewGroups in it. Each ViewGroup interaction is dependent on data from a database. I'm using an AsyncTask to read from a database and return a Cursor when it's done. Before the AsyncTask is executed, I just want to display a single View in the ViewFlipper saying "Loading data, please wait.", is this possible somehow?


Show the progress dialog in your onPreExecute() and dismiss it in the onPostExecute(). Something like this,

private class MyAsyncTask extends AsyncTask<Integer, Integer, Integer[]> {
    private ProgressDialog myWait = null;

    // This is on the UI thread itself
    protected void onPreExecute() {
        myWait  = new ProgressDialog(MainActivity.this);
        myWait.setMessage("Loading data, please wait");
        myWait.setCancelable(false);
        myWait.show();
    }

    // Separate worker thread is used here 
    protected Integer[] doInBackground(Integer...params) {
        //do the database loading
        return <your result - goes to onPostExecute>;
    }

    // This is on the UI thread itself
    protected void onPostExecute(Integer[] resultCell) {
        if (myWait  != null) {
            myWait.dismiss();
        }
    }
}


yes you can make use of progressDialog. Do it like this,

progressDiaolg=ProgressDialog.show(Activity.this,"","Loading Images...");
 final Thread t=    new Thread(new Runnable() {
                            public void run() {
                                Log.i("Inside Thread", "Downloading Images...");

                                downloadImages();

                              handler.sendEmptyMessage(0);

                            }

                        });
    t.start();
    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            try {

                progressDiaolg.dismiss();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
        }

    };

I don't have idea with Asynctask. So try modifying this snippet accordingly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜