Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to return two different views from getView in adapter
    primarykey
    data
    text
    <p>Developing my very first app I'm trying to add sections to my elements in a list view. All items a have a date and I want to return a simple layout containing a date each time the date changes. In my adapter I have the following:</p> <pre><code> 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; } </code></pre> <p>Everything works just fine until I reach the very last line:</p> <pre><code>return convertView; </code></pre> <p>Adding a break point to that line and trying to step passed it immediately throws some sort of error.</p> <p>Now being new to Android and Eclipse I really can't find a stacktrace similar to what I get when coding .Net in Visual Studio. All I can see is that in the Debug perspective in Eclipse a tab with AbsListView.class is opened...</p> <p>Can anyone make any sense of what I'm trying to achieve? And maybe help out a bit? I looked at <a href="http://android.cyrilmottier.com/?p=232" rel="nofollow">this link</a> and as far as I can tell he also returns two different views depending on item type :-?</p> <p>Edit: Implemented Streets Of Bostons answer and changed the code to</p> <pre><code>@Override public int getItemViewType(int position) { Match match = matchArrayList.get(position); if (match.HomeTeam == "") { return 0; } else { return 1; } } </code></pre> <p>Now it works but scrolling in my list FC's my app</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload