如何在android中的事件上添加图像
我是安卓新手。在我的应用程序中,我想添加一个进程栏(图像),这应该表明某些内容正在进行中,完成后隐藏此进程栏。
就像我添加用户详细信息一样,单击添加按钮时应该显示此进程栏。
我该怎么做,请建议。
谢谢。
我使用的代码:
progressDialog = ProgressDialog.show(AddTicketActivity.this, "", "Loading...");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
它的问题是,它是硬编码的sleep(10000)
,而我想要的是它取决于我的进程添加或添加所需的时间获取数据。
我不知道在哪里放置在按钮单击时执行的代码。
我希望你明白我的意思,
再次感谢。
I am new to Android. In my application I want to add an process bar(an image), this should indicate that something is in process and after completion hide this precess bar.
As if i add user detail, On click on add button this process bar should be displayed.
How can i do it, please suggest.
Thanks.
Code I used:
progressDialog = ProgressDialog.show(AddTicketActivity.this, "", "Loading...");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
The problem with it is , it is hardcoded sleep(10000)
whereas what i want is it to be dependent on how much time my process takes to add or fetch data.
I am not getting where to put code which is executing on onclick of button.
I hope you got my point
Thanks again.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,您可以使用 ProgressDialog 或进度栏。
现在,要显示进度栏并在后台执行任务期间,您应该实现 AsyncTask< /a>.
progressbar.setVisibility(View.VISIBLE);
progressbar.setVisibility(View.INVISIBLE);
隐藏 ProgressBarFor that you can use either ProgressDialog or ProgressBar.
Now, To display Progress bar and during that perform task in background, you should implement AsyncTask.
progressbar.setVisibility(View.VISIBLE);
progressbar.setVisibility(View.INVISIBLE);
如果您只想显示图像,您可以将其放置在具有visibility=gone 的RelativeLayout 上
,然后只需控制何时显示或隐藏它。
另一种方式是 Android 中典型的 progressDialog
Well if you just want to show an image, you can place it on a RelativeLayout with visibility=gone
and then just control when to show or hide it.
another way is the typical progressDialog in Android
或者使用进度条(旋转轮),它对用户更友好,对机器人也更友好。
看一下 Eclipse 上的 Form 小部件。
Or use a progress bar (spinning wheel) it's more user friendly and droid friendly .
Take a look at the Form widgets on Eclipse .