私はRelativeLayout
を持っています。私はListView
とProgressBar
を持っています。 ListView
は他の要素の下にあり、ProgressBar
は画面の中央に表示されます。ListView上でProgressBarフロントを持ちます
ここではAsyncTask
を使用し、ListView
にデータを読み込み、これを実行している間にProgressBar
を表示します。
リストが空の場合、ProgressBar
が表示されます。しかし、リストにいくつかの要素があり、リスト内のデータを読み込んでリフレッシュしようとすると、ProgressBar
は表示されません。これはおそらく、ListView
がアダプタを設定すると(ProgressBar
の上に)表示されているためです。
私はprogressbar.bringtofront()
を使ってみましたが、運はありませんでした。
ここは私のレイアウトです。
<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"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
...
<com.nhaarman.listviewanimations.itemmanipulation.DynamicListView
android:id="@+id/favourites_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/refresh_button"
android:divider="@null"
android:paddingTop="10dp" />
<ProgressBar
android:id="@+id/refresh_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
</RelativeLayout>
私は私のAsyncTask
で.get()
を使用しているので、私はAsyncTask
でそれを伝統的な方法を更新するのではなく、Activity
自体にProgressBar
を更新します。ここでは、私はProgressBar
を表示して非表示に使用するコードです。
//before i send the asynctask
refreshProgress.setVisibility(View.VISIBLE);
refreshProgress.bringToFront();
ArrayList<String> response = task.execute(new String[]{url}).get();
...
//after parsing the response and setting the adapter for the listview
favoritesAdapter.notifyDataSetChanged();
favoritesAdapter = new FavoritesAdapter(this, main_company, main_symbol, main_price, main_change, main_marketcap);
favoritesListView.setAdapter(favoritesAdapter);
refreshProgress.bringToFront();
refreshProgress.setVisibility(View.INVISIBLE);
私はAsyncTask
を使用しながらProgressBar
がListView
の上部に表示されるようにしたいです。
ありがとうございます!
いいね。ありがとう!しかし私は私のケースでは 'ProgressBar'を使う必要があります。 –