Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is not enough info in your questions. However, i'll try my best :-)</p> <p>If you return more than one (type of) <code>View</code> (<code>R.layout.date_separator</code> or <code>R.layout.match_layout</code>), you have to implement the adapter's <code>getViewTypeCount</code> and <code>getItemViewType</code> methods:</p> <pre><code>@Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { Match match = matchArrayList.get(position); ... ... if (!sDate.equals(_lastDate)) { return 0; // matches R.layout.date_separator } else { return 1; // matches R.layout.match_layout } } </code></pre> <p>It has to do with the recycling of Views. When <code>convertView != null</code>, you have to make sure that the parameter <code>convertView</code> matches the original inflation of the <code>convertView</code> done at an earlier time. The method <code>getItemViewType</code> makes sure of that.</p> <p>Here is a <strong>suggested</strong> <code>getView</code> implementation:</p> <ul> <li>The inflation of the <code>convertView</code> is not entirely driven by <code>getItemViewType</code></li> <li>Switched the if and else in the second if statement (<code>SeparatorHolder</code> and <code>MatchHolder</code> were switched in calling <code>convertView.getTag</code>)</li> </ul> <p>.</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; int itemType = getItemViewType(position); if (convertView == null) { if (itemType == 0) { 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 (itemtype == 0) separatorHolder = (SeparatorHolder) convertView.getTag(); else matchHolder = (MatchHolder) convertView.getTag(); } if (itemType == 0) { _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>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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