首页 \ 问答 \ ProgressBar的可见性(Visibility of ProgressBar)

ProgressBar的可见性(Visibility of ProgressBar)

当用户点击一个活动中的按钮时,我需要处理一些数据,所以屏幕看起来像应用程序停止2-3秒。 这不是很多,但我想给用户提供一切正常的信息,IMO最好的办法就是进度条,只有在处理数据时才能看到进度条。

我找到了ProgressBar的代码,它看起来像这样:

    <ProgressBar
    android:id="@+id/loadingdata_progress"
    style="?android:attr/progressBarStyle"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/fin2_note"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"
    android:visibility="invisible" />

并将其插入到我的版面中间。

而要尝试进度条的工作,我把这个代码

loadingimage= (ProgressBar) findViewById(R.id.loadingdata_progress); loadingimage.setVisibility(View.VISIBLE);

onCreate方法,一切都很好。 然后我重新创建了代码,只有在处理数据时才显示此进度条。

点击用户调用此方法后

   public void fin2_clickOnFinalization(View v)
   {    

            loadingimage= (ProgressBar) findViewById(R.id.loadingdata_progress);
    loadingimage.setVisibility(View.VISIBLE);

          // code where data is processing
            loadingimage.setVisibility(View.INVISIBLE);
       }

屏幕上没有任何内容出现。 我不知道错误在哪里。 如果我通过id找到了进度条,我很奇怪我可以在onCreate方法中控制它,但在onclick方法中,它超出了我的控制范围。


I need to process some data when the user click the button in one activity, so the screen looks like the app stops for 2-3 seconds. It isn't a lot but I want to give the user information that everything is ok and IMO the best way will be the progressbar which is visible only when data are processed.

I found the code of ProgressBar and it looks like this:

    <ProgressBar
    android:id="@+id/loadingdata_progress"
    style="?android:attr/progressBarStyle"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignBottom="@+id/fin2_note"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"
    android:visibility="invisible" />

and inserted it on the middle of my layout.

And to try if the progressbar works, I put this code

loadingimage= (ProgressBar) findViewById(R.id.loadingdata_progress); loadingimage.setVisibility(View.VISIBLE);

into onCreate method and everything looks fine. Then I recreated the code to show this progressbar only if the data is processed.

After click the user invoke this method

   public void fin2_clickOnFinalization(View v)
   {    

            loadingimage= (ProgressBar) findViewById(R.id.loadingdata_progress);
    loadingimage.setVisibility(View.VISIBLE);

          // code where data is processing
            loadingimage.setVisibility(View.INVISIBLE);
       }

and nothing appear on the screen. I don't know where is the mistake. If I found the progress bar by id, It's strange for me that I can control it in onCreate method but in onclick method it's out of my control.


原文:https://stackoverflow.com/questions/19005014
更新时间:2023-04-20 07:04

最满意答案

Alertprompt不是DOM的一部分,它们是浏览器的一部分。 你不能从代码中模拟它们的调用行为。


Alert & prompt are not part of DOM, they are part of browser. You can't simulate their invoke behavior from your code.

相关问答

更多
  • 这是一个很好的 精细上传程序演示 它是一个控件本身。 但是一个div被放置在那里,并且CSS应用来获得这种感觉。 文件控制的不透明度设置为0,以便在点击div时看起来对话窗口打开。 Here is a nice one Fine Uploader demo It is an control itself. But a div is placed over that and css styles are applied to ...
  • 您无法使用标准的javascript弹出窗口执行此操作。 您需要使用自定义库,例如下面之一: jQueryUI的 MooTools的 原型 Scriptaculous的 雅虎用户界面 You can't do this with standard javascript popups. You'll need to use a custom library such as one of the below: jQueryUI MooTools Prototype Scriptaculous Yahoo Use ...
  • 对于可以输入值的对话框,您可以使用jQuery编写代码来自己生成对话框。 但是,当你拥有像jQuery UI或bootstrap这样的框架时,为什么要重新发明轮子。 下面是使用HTML 5,jQuery, Bootstrap的示例