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:
- Extend the AsyncTask
- Start the progress dialog in onPreExecute()
- Define the background task in doInBackground(Params...)
- Define updating of the progress dialog in onProgressUpdate(Progress...)
- Update dialog by calling publishProgress() from doInBackground()
- Start a new Dialog #2 in onPostExecute().
精彩评论