最初のアプリを開発して、リスト ビューの要素にセクションを追加しようとしています。すべてのアイテムには日付があり、日付が変わるたびに日付を含む単純なレイアウトを返したいと考えています。私のアダプターには次のものがあります。
public View getView(int position, View convertView, ViewGroup parent) {
Match match = matchArrayList.get(position);
Calendar matchTime = match.getDate();
SimpleDateFormat date = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat time = new SimpleDateFormat("HH:mm");
String sDate = date.format(matchTime.getTime());
SeparatorHolder separatorHolder = null;
MatchHolder matchHolder = null;
if (convertView == null) {
if (!sDate.equals(_lastDate)) {
convertView = inflator.inflate(R.layout.date_separator, null);
separatorHolder = new SeparatorHolder();
separatorHolder.Date = (TextView) convertView.findViewById(R.id.date);
convertView.setTag(separatorHolder);
} else {
convertView = inflator.inflate(R.layout.match_layout, null);
matchHolder = new MatchHolder();
matchHolder.Time = (TextView) convertView.findViewById(R.id.time);
matchHolder.HomeTeam = (TextView) convertView.findViewById(R.id.homeTeam);
matchHolder.AwayTeam = (TextView) convertView.findViewById(R.id.awayTeam);
matchHolder.HomeTeamImage = (ImageView) convertView.findViewById(R.id.homeTeamImageView);
matchHolder.AwayTeamImage = (ImageView) convertView.findViewById(R.id.awayTeamImageView);
matchHolder.TournamentImage = (ImageView) convertView.findViewById(R.id.tournamentImageView);
matchHolder.TVChannelImage = (ImageView) convertView.findViewById(R.id.tvChannelImageView);
convertView.setTag(matchHolder);
}
}
else {
if (!sDate.equals(_lastDate))
matchHolder = (MatchHolder) convertView.getTag();
else
separatorHolder = (SeparatorHolder) convertView.getTag();
}
if (!sDate.equals(_lastDate)) {
_lastDate = sDate;
separatorHolder.Date.setText(sDate);
} else {
UrlImageViewHelper.setUrlDrawable(matchHolder.TournamentImage, match.getTournamentImage());
UrlImageViewHelper.setUrlDrawable(matchHolder.HomeTeamImage, match.getHomeTeamImage());
matchHolder.HomeTeam.setText(match.getHomeTeam());
UrlImageViewHelper.setUrlDrawable(matchHolder.AwayTeamImage, match.getAwayTeamImage());
matchHolder.AwayTeam.setText(match.getAwayTeam());
matchHolder.Time.setText(time.format(matchTime.getTime()));
UrlImageViewHelper.setUrlDrawable(matchHolder.TVChannelImage, match.getTVChannelImage());
}
return convertView;
}
最後の行に到達するまで、すべてが正常に機能します。
return convertView;
その行にブレークポイントを追加し、それを通過してステップ実行しようとすると、すぐに何らかのエラーがスローされます。
Android と Eclipse を初めて使用するようになったので、Visual Studio で .Net をコーディングするときに得られるようなスタックトレースを実際に見つけることができません。私が見ることができるのは、EclipseのDebugパースペクティブでAbsListView.classのタブが開かれていることだけです...
誰でも私が達成しようとしていることを理解できますか? で、ちょっと手伝って?私はこのリンクを見ましたが、私が知る限り、彼はアイテムタイプに応じて2つの異なるビューも返します:-?
編集: Streets Of Bostons の回答を実装し、コードを次のように変更しました
@Override
public int getItemViewType(int position) {
Match match = matchArrayList.get(position);
if (match.HomeTeam == "") {
return 0;
}
else {
return 1;
}
}
今は動作しますが、リスト内でスクロールします FC のマイ アプリ
前もって感謝します