2012-05-01 66 views
1

我有一個片段包含一個列表,現在這個片段擁有的listView,它的數據從webserver我想要顯示一個加載視圖,直到數據到適配器。我如何改變一個片段的contentView?更改片段contentView android

回答

0

我已經通過使用包含ListView和ProgressBar的RelativeLayout完成了這項工作,其中ProgressBar設置爲View.INVISIBLE。在從ProgressBar應該讓我可見的Web服務器中檢索數據之前。當數據到達時,只填充ListView並使ProgressBar再次不可見。

佈局:

<ListView 
     android:id="@+id/list" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     /> 

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

</RelativeLayout> 

代碼:

ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress); 
progressBar.setVisibility(View.VISIBLE); 
// retrieve data ... 
// populate ListView 
progressBar.setVisibility(View.INVISIBLE);