2013-02-13 65 views
1

当应用程序启动时,我从main.xml文件显示一个进度条,直到列表为空。一旦列表填充了来自URL的数据,我应该关闭此进度条。 如何在不使用进度对话框的情况下做到这一点?Android - 自动关闭进度条

我的main.xml

<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" 
    tools:context=".MainActivity" > 

    <ListView 
     android:id="@+id/list_view_places" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:drawSelectorOnTop="false" 
     android:fastScrollEnabled="true" > 
    </ListView> 

    <ProgressBar 
     android:id="@+id/empty_progress_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 
+1

看看这个链接http://stackoverflow.com/questions/3771568/how-to-show-empty-view-when-listview-is-empty – Nishant 2013-02-13 13:19:15

+0

感谢您的链接。这是正确的。 – 2013-02-13 13:30:33

回答

8

试着这么做:

ProgressBar bar = (ProgressBar) findViewById(R.id.empty_progress_bar); 
bar.setVisibility(View.GONE); 
+0

此解决方案有效。替代方法是listview.setEmptyView(prog_bar); – 2013-02-13 13:34:35

3

如果您将使用列表片段,然后进度条会自动处理。一旦数据被填充,它将自动解除。