ProgressBar beim Laden von ListView (mit AsyncTask)
Ich versuche, beim Laden einer benutzerdefinierten ListView einen Fortschrittsbalken anzuzeigen und anschließend auszublenden. Ich verwende eine ASync-Aufgabe, aber aus irgendeinem Grund - Die Inhaltsansicht wird nicht festgelegt und die vorherige Layoutansicht bleibt hängen, bis die gesamte Listenansicht geladen ist.
Hier ist mein Code:
private ListView listViewGameResults;
protected View dialogLayout;
protected ArrayList<Game> listGames;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.adresults);
GameResultsLoader gameResultsLoader = new GameResultsLoader();
gameResultsLoader.execute();
}
private class GameResultsLoader extends AsyncTask<Void, Void, Void> {
private GameResultsAdapter adapter;
public GameResultsLoader() {
}
@Override
protected void onPreExecute() {
}
@Override
protected Void doInBackground(Void... params) {
try {
listGames = GameResultsCache.getInstance().getGameResults();
adapter = new GameResultsAdapter(getBaseContext(), listGames);
listViewGameResults = (ListView)findViewById(R.id.listViewGameResults);
}
catch (Exception e) {
// TODO Auto-generated catch block
finish();
}
return null;
}
@Override
protected void onPostExecute(Void res) {
listViewGameResults.setAdapter(adapter);
listViewGameResults.setDivider(null);
listViewGameResults.setDividerHeight(0);
ProgressBar pb = (ProgressBar)findViewById(R.id.progressbar_loading);
pb.setVisibility(View.GONE);
}
}
ProgressBar und ListView in meinem Layout:
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_centerInParent="true"
android:id="@+id/progressbar_loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/listViewGameResults"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dip"
android:layout_below="@+id/upperstrip"
android:layout_above="@+id/ivDownStrip" />