如何在android中的事件上添加图像

发布于 2024-12-13 00:12:27 字数 726 浏览 2 评论 0原文

我是安卓新手。在我的应用程序中,我想添加一个进程栏(图像),这应该表明某些内容正在进行中,完成后隐藏此进程栏。

就像我添加用户详细信息一样,单击添加按钮时应该显示此进程栏。

我该怎么做,请建议。

谢谢。

我使用的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光无声 2024-12-20 00:12:27

为此,您可以使用 ProgressDialog进度栏

现在,要显示进度栏并在后台执行任务期间,您应该实现 AsyncTask< /a>.

  1. 在 onPreExecute() 方法中,显示 ProgressBar 或使其再次可见,如下所示: progressbar.setVisibility(View.VISIBLE);
  2. 在 doInBackground() 方法中,执行后台任务,即在您的案例中添加用户详细信息
  3. 在 onPostExecute() 方法中,只需使用 progressbar.setVisibility(View.INVISIBLE); 隐藏 ProgressBar

For that you can use either ProgressDialog or ProgressBar.

Now, To display Progress bar and during that perform task in background, you should implement AsyncTask.

  1. In onPreExecute() method, display the ProgressBar or make it visible again like: progressbar.setVisibility(View.VISIBLE);
  2. In doInBackground() method, perform the background task, i.e. add user detail in your case
  3. In onPostExecute() method, just hide the ProgressBar using the progressbar.setVisibility(View.INVISIBLE);
乱了心跳 2024-12-20 00:12:27

如果您只想显示图像,您可以将其放置在具有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

陌伤ぢ 2024-12-20 00:12:27

或者使用进度条(旋转轮),它对用户更友好,对机器人也更友好。
看一下 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 .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文