アプリケーションに次のクラスがあります。
public class Player implements Parcelable {
private String name;
private int playerColor;
private int[] scores;
...
}
関連するリストビューに表示するスコア配列の要素を ArrayAdapter の getView メソッドに伝えるにはどうすればよいですか? アクティビティからの情報に基づいて、ListView に player.name フィールドと、player.scores 配列の特定の要素を表示したいと考えています。
public class PlayerGameAdapter extends ArrayAdapter<Player> {
private ArrayList<Player> entries;
private Activity activity;
public PlayerGameAdapter(Activity a, int viewResourceId, ArrayList<Player> entries) {
super(a, viewResourceId, entries);
this.entries = entries;
this.activity = a;
}
public static class ViewHolder {
public Button buttonName;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi =
(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.listview_row_player_game, null);
holder = new ViewHolder();
holder.buttonName = (Button) v.findViewById(R.id.buttonGamePlayerListName);
v.setTag(holder);
} else
holder = (ViewHolder) v.getTag();
final MiniGolfPlayer player = entries.get(position);
if (player != null) {
holder.buttonName.setText(player.getName() + " - " + player.scores[ELEMENT]);
}
return v;
}
}