解決策を見つけました!
ViewFlipper の代わりに ViewPager を使用するようになりました。ビューは、run() メソッド内で生成され (Web からデータを取得したため、既に存在します)、Map に保存されます。私のハンドラーでは、pagerAdapter.notifyDataSetChanged() を呼び出すだけで、pagerAdapter はビューのマップを使用し、スムーズかつ高速に動作します。だから私は今、ViewPager を無限にスクロールさせる方法を探していますが、それはこれとは関係のない別の問題です ;)
皆さんの回答に感謝し、引き続き良いサポートを続けてください。
私はAndroid開発にまったく慣れておらず、(巨大な)レイアウトを膨らませているときに問題に直面しています。正常に動作する Webservice からデータを取得し、Activity 内でハンドラーを使用してこのデータをフロントエンドに取り込みます。これが私のhandleMessageです:
public void handleMessage(Message msg) {
LayoutInflater inflater = getLayoutInflater();
List<Integer> gamedays = new ArrayList<Integer>(games.keySet());
Collections.sort(gamedays);
for (Integer gameday : gamedays) {
View gamedaytable = inflater.inflate(R.layout.gamedaytable, null);
TableLayout table = (TableLayout) gamedaytable.findViewById(R.id.gameDayTable);
table.removeAllViews();
List<Game> gamelist = games.get(gameday);
int rowcount = 2;
for (Game game : gamelist) {
View tableRow = inflater.inflate(R.layout.gamedayrow, null);
TextView homeTeam = (TextView) tableRow.findViewById(R.id.gameDayHome);
TextView awayTeam = (TextView) tableRow.findViewById(R.id.gameDayAway);
TextView gameResult = (TextView) tableRow.findViewById(R.id.gameDayResult);
gameResult.setBackgroundResource(R.drawable.resultbackground);
homeTeam.setText(game.getHomeTeam().getName());
awayTeam.setText(game.getAwayTeam().getName());
if (game.getHomegoals() < 0 || game.getAwaygoals() < 0) {
gameResult.setText("-:-");
} else {
gameResult.setText(game.getHomegoals() + ":" + game.getAwaygoals());
}
if (rowcount % 2 == 0) {
tableRow.setBackgroundColor(0xffdee0dd);
} else {
// setting alternative background
tableRow.setBackgroundColor(0xfff1f3f0);
}
rowcount++;
table.addView(tableRow);
}
flipper.addView(gamedaytable);
}
flipper.setDisplayedChild(thisgameday - 1);
pd.dismiss();
}
私の問題は、このコードの実行が非常に遅く、プロセスダイアログが消えてレイアウトが表示される前に約 1 秒間フリーズすることです。ゲームは、9 つのエントリを含む 34 のエントリで構成されます。だから私はテーブルを保持するrelativeLayout()で構成される34のビューを追加しています。問題は、Androidがレイアウトの描画と計算を開始し、これに時間がかかりすぎることです。私が正しければ、私は AsynTask を使用できません。なぜなら、そこで UI を行うことができず、UI のみを行うからです。
これを行っている間、プロセスダイアログがフリーズしないようにする方法を探しています。それとも、私は完全に間違ったことをしているのかもしれません
R.layout.gamedaytable:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff1f3f0"
android:focusableInTouchMode="false" >
<TableLayout
android:id="@+id/gameDayTable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:focusableInTouchMode="false" >
</TableLayout>
</RelativeLayout>
R.layout.gamedayrow:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusableInTouchMode="false"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/gameDayHome"
style="@style/textsizeSmallScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Mannschaft 1" />
<TextView
android:id="@+id/textView2"
style="@style/textsizeSmallScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text=":" />
<TextView
android:id="@+id/gameDayAway"
style="@style/textsizeSmallScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mannschaft 2" />
<TextView
android:id="@+id/gameDayResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:background="@drawable/resultbackground"
android:paddingLeft="10dip"
android:text="0:5"
android:textColor="#FFFFFF"
android:textSize="11dp"
android:textStyle="bold"
android:typeface="monospace" />
</TableRow>
追加情報: テーブルは次のようになります。したがって、これが本当にListViewであるべきかどうかはわかりません。私にとってはテーブルデータだからです;)