我是新android开发。我想开发一个对话框
与进度
在我的应用程序。当我点击搜索按钮对话框
应该出现与进度
,显示出进度切换到之前回事另一个活动
。请给我建议样品code。
I am new to android development. I want to develop a dialog
with a progressbar
in my application. When i click the search button the dialog
should appear with the progressbar
, showing that the progress is going on before switching to another activity
. Please suggest me with sample code.
使用 ProgressDialog
。你应该做一个新的线程的工作
,不过,并使用处理
回调到活动
时结束。下面是我如何做到这一点:
Use a ProgressDialog
. You should do the work on a new thread
, though, and use a handler
to call back to the activity
when finished. Here's how I do it:
private ProgressDialog pd;
private View.OnClickListener searchClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
pd = ProgressDialog.show(MyActivity.this, "Searching...", "Searching for matches", true, false);
new Thread(new Runnable() {
public void run() {
//do work
//.....
finishedHandler.sendEmptyMessage();
}
}).start();
}
}
private Handler finishedHandler = new Handler() {
@Override public void handleMessage(Message msg) {
pd.dismiss();
//start new activity
}
}
上一篇:Twig:工作国际化 (i18n) 示例示例、工作、Twig、i18n
下一篇:在带有 Symfony2 的 Twig 中使用 {% stylesheets %} 标签时通过 Twig 运行 CSS 文件标签、文件、Twig、CSS