开发者

Progress Dialog

-->I am new to Android And i want to show two progress dialog one after another??

-->First i want to show when my image is load from internet, when this process is done i have set A button on that Remote image.

-->When i click that button 开发者_运维百科i want Dialog for second time..(on clicking button i have set video streaming code.. before video is start i want to close that Dialog..)

Any Help???? Thanks...


You can create 2 threads. First for image when it is loaded then call another thread of video. Make two runnable actions and two handlers to handle that

public void onCreate(Bundle savedInstanceState) {
    ProgressDialog pd = ProgressDialog.show(this, "","Please Wait", true, false);

    Thread th = new Thread(setImage);
    th.start();

}

public Runnable setImage = new Runnable() {
    public void run() {
        //your code 
        handler.sendEmptyMessage(0);
    }
};

private Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        if (pd != null)
            pd.dismiss();
    }
};


On Android it's best to use AsyncTask to execute tasks in the background while still updating UI:

  1. Extend the AsyncTask
  2. Start the progress dialog in onPreExecute()
  3. Define the background task in doInBackground(Params...)
  4. Define updating of the progress dialog in onProgressUpdate(Progress...)
  5. Update dialog by calling publishProgress() from doInBackground()
  6. Start a new Dialog #2 in onPostExecute().
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜