我有EditText
,Button
和ListView
的观点。 按钮的onClick()
解析某个网站(此部分工作正常),但它需要一些时间才能在ListView
中显示解析的信息,因此我想在该地点显示小型ProgressBar
,其中ListView
应在一段时间后发生。如何在做一些工作时在视图上显示ProgressBar?
所以,我想补充这我的布局(这里我写的重要组成部分):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/layout1"
android:weightSum="1.0">
<EditText
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight=".86" />
<ImageButton
android:layout_height="match_parent"
android:layout_width="0px"
android:layout_weight=".14" />
</LinearLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_below="@id/layout1"
android:gravity="center"
android:layout_centerInParent="true"
android:id="@+id/progressbar" >
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="@android:style/Widget.ProgressBar.Small" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layout1">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
在源代码中:
progressBar = (RelativeLayout) findViewById(R.id.progressbar);
每次我想要显示的ProgressBar
,我这样做:
progressBar.setVisibility(View.VISIBLE);
禁用:
progressBar.setVisibility(View.INVISIBLE);
但这不起作用。
我该如何解决这个问题?
*但这不起作用。* - 这不是很有帮助。更好地解释什么是问题? – Luksprog
我看不到任何显示的“ProgressBar”。它的工作原理与不添加ProgressBar琐事一样。 – azizbekian
同意Luksprog,但我会愿意猜你的解析是封锁(所以setvisibility代码不会执行,直到解析后)。有很多方法可以解决这个问题,但我会建议搜索progressbar和asynctask(还有其他的方法可以完成这个任务,但基本上你需要在你做同时启动一个非阻塞的displayprogressbar方法解析,然后在返回之前在displayprogressbar中检查完成解析过程)。 – logray