0

I have a AsyncTask, which fetch data from the web. These data should be written into a ListView.

I show a progressbar in the fragment of AListFragment.

public class AListFragment extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {     
        View rootView = inflater.inflate(R.layout.progress_bar, container, false);
        return rootView;
    }   
}

progress_bar.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:id="@+id/loadOverviewStatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:visibility="gone" >

    <ProgressBar
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp" />

    <TextView
        android:id="@+id/login_status_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:fontFamily="sans-serif-light"
        android:text="Loading..."/>
</LinearLayout>

How can i change the layout of the fragment, in the OnPostExecute of the asynctask , that i get a ListView?

4

1 回答 1

0

您不需要更改 Fragment 布局,只需使 Layout 女巫包含一个ListViewand Progressbar,并创建两个功能:
1-showLoading()女巫将显示progressbar和隐藏ListView
2-hideLoading()隐藏Progressbar并显示ListView

当您开始加载数据呼叫showLoading()时,当您完成呼叫时hideLoading()

于 2013-07-18T09:32:33.297 回答