如何在做一些工作显示视图上进度? [英] How to display a ProgressBar on a View while doing some work?

查看:142
本文介绍了如何在做一些工作显示视图上进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有的EditText 按钮视图的ListView
巴顿的的onClick()解析一些网站(这部分工程确定),但它需要一些时间来显示的ListView ,所以我想在这个地方,显示小进度其中的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆