如何启动和Android的动态完成进度 [英] How to start and finish progressBar dynamically in android
问题描述
当我跳过从第一个活动第二类活动课,我将开始imageprocessing某些图像中第二个活动,然后,直到新的图像来筛选我Wnt信号来启动进度条,然后完成时,新的图像来筛选。我怎样才能做到这一点?
When I skip second activity class from first activity class, I will start imageprocessing on certain image in second activity and then until new image comes to screen I wnt to start progress bar and then finish when the new image comes to screen. How can I do this ?
推荐答案
使用ProgreaaDialog和AsyncTask的。你西港岛线让您soultion 使用的AsyncTask在doBackInGroundProcess做图像处理。而在doPostExecute()退出或取消进度对话框
Use ProgreaaDialog and AsyncTask. you wil get your soultion Use AsyncTask in doBackInGroundProcess do image processing. and in doPostExecute() exit or cancel the progress dialog
对样品code看看。
要启动AsyncTsk使用新ProgressTask()执行(空);
从那里你想要做图像处理的活动。
have a look on the sample code.
To start AsyncTsk use new ProgressTask().execute(null);
from the activity where you want to do image processing.
private class ProgressTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog;
List<Message> titles;
private ListActivity activity;
//private List<Message> messages;
public ProgressTask(ListActivity activity) {
this.activity = activity;
context = activity;
dialog = new ProgressDialog(context);
}
/** progress dialog to show user that the backup is processing. */
/** application context. */
private Context context;
protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.show();
}
@Override
protected void onPostExecute(final Boolean success) {
List<Message> titles = new ArrayList<Message>(messages.size());
for (Message msg : messages){
titles.add(msg);
}
MessageListAdapter adapter = new MessageListAdapter(activity, titles);
activity.setListAdapter(adapter);
adapter.notifyDataSetChanged();
if (dialog.isShowing()) {
dialog.dismiss();
}
if (success) {
Toast.makeText(context, "OK", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Error", Toast.LENGTH_LONG).show();
}
}
protected Boolean doInBackground(final String... args) {
try{
BaseFeedParser parser = new BaseFeedParser();
messages = parser.parse();
return true;
} catch (Exception e){
Log.e("tag", "error", e);
return false;
}
}
}
}
有一个看看这里
这篇关于如何启动和Android的动态完成进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!