如何在做一些工作显示视图上进度? [英] How to display a ProgressBar on a View while doing some work?
问题描述
我有的EditText
,按钮视图
和的ListView
。
巴顿的的onClick()
解析一些网站(这部分工程确定),但它需要一些时间来显示的ListView $ C $的解析信息C>,所以我想在这个地方,显示小
进度
其中的ListView
一段时间后应该发生。
I have a view with EditText
, Button
and ListView
.
Button's onClick()
parses some site (this part works OK), but it takes some time to display the parsed info in ListView
, so I want to display small ProgressBar
on the place, where the ListView
should take place after a while.
所以,我将它添加到我的布局(我在这里写的重要组成部分):
So, I add this to my layout (I write important part here):
<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>
在源$ C $ C:
In source code:
progressBar = (RelativeLayout) findViewById(R.id.progressbar);
和每次我想要显示的进度
,我这样做:
And everytime I want to show the ProgressBar
, I do this:
progressBar.setVisibility(View.VISIBLE);
禁用:
progressBar.setVisibility(View.INVISIBLE);
但是,这并不正常工作。
But this doesn't work.
我如何来解决这一问题?
How can I work this out?
推荐答案
对于那些,谁感兴趣的答案。
For those, who are interested in the answer.
主要标记只写了。
<RelativeLayout
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_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layout1" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout1" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/layout1"
android:gravity="center"
android:visibility="gone"
android:background="#DDE7E7E8"
android:id="@+id/pBar" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Small" />
</LinearLayout>
</RelativeLayout>
以及的AsyncTask
:
private class Parsing extends AsyncTask<Void, Void, Void>
{
private LinearLayout pBar;
private Parsing()
{
pBar = (LinearLayout) findViewById(R.id.pBar);
}
@Override
protected Void doInBackground(Void... params)
{
parsingHere();
return null;
}
@Override
protected void onPreExecute()
{
super.onPreExecute();
pBar.setVisibility(View.VISIBLE);
}
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
pBar.setVisibility(View.INVISIBLE);
}
}
这篇关于如何在做一些工作显示视图上进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!