Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since you are using a the Viewholder-pattern and recycle views, you end up with jumble. This is because you have two different kind of views in your list, and when you get a convertview, it will be one of those views.</p> <p>Imagine a dataset A with layout/view a, and same for B b</p> <p>(-B- means it is not shown on screen yet) So if your initial list is Aa, Bb, Bb, Aa, -B- , -B- and you scroll to bring data B into the list.. Then you will get a convertview with layout a OR layout b , thus having no way to use the convertview reliably. </p> <p>I am doing some searching to find a way to support different views in a ListView and at the same time use the convertView/viewHolder-pattern.. So far I have found this one to be interesting: <a href="https://github.com/commonsguy/cwac-merge#readme" rel="nofollow">https://github.com/commonsguy/cwac-merge#readme</a></p> <p>What you want to do is to override the getItemViewType (position) . Here is an example. You of course have your dataTypes instead of MoreResultsLoader and YPContact .</p> <pre><code>@Override public int getItemViewType(int position) { if (resultsList.get(position) instanceof MoreResultsLoader) { return VIEW_TYPE_MORE_RESULTS_LOADER; } if (resultsList.get(position) instanceof YPContact) { YPContact ypCon = (YPContact) resultsList.get(position); if(checkForGold(ypCon)) return VIEW_TYPE_YPCONTACT_GOLD; else return VIEW_TYPE_YPCONTACT_REG; } } </code></pre> <p>Then in getView , you would need to check which view type you are dealing with and inflate/populate with the correct ViewHolder class.</p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { View ourView = convertView; int itemViewType = getItemViewType(position); switch (itemViewType) { case VIEW_TYPE_MORE_RESULTS_LOADER: MoreResultsViewHolder moreResVH = null; if (ourView == null) { ourView = layoutInflator.inflate(R.layout.load_more_items, null, true); moreResVH = new MoreResultsViewHolder(ourView); ourView.setTag(moreResVH); } else { moreResVH = (MoreResultsViewHolder) ourView.getTag(); } if (moreResVH != null) { moreResVH.populate((MoreResultsLoader) resultsList .get(position), context); } return ourView; case VIEW_TYPE_YPCONTACT_GOLD: ContactViewHolderGold contactVHGold = null; if (ourView == null) { ourView = layoutInflator.inflate( R.layout.yp_search_result_list_item_gold, null, true); contactVHGold = new ContactViewHolderGold(ourView); ourView.setTag(contactVHGold); } else { contactVHGold = (ContactViewHolderGold) ourView.getTag(); } if (contactVHGold != null) { final YPContact ypContact = (YPContact) resultsList .get(position); contactVHGold.populate(ypContact, mCurrentLocation, ypSearchResultsActivity); // moreResVH.populate( // (MoreResultsLoader)resultsList.get(position),context); } return ourView; </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. 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.
 

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