Skip to content Skip to sidebar Skip to footer

Update Adapter From Different Method

I have a arrayadapter.I am listing items with this. My code: static class ViewHolder { TextView nameView; ImageView imageView; BadgeView badge; }

Solution 1:

You can get the view with

ViewHoldervh= (ViewHolder) randomAdapter.getItem(position).getTag()
vh.badge.show();

checkout get item

Edit: Sorry about that wrong method

Solution 2:

Try this (not tested) code :

intvisiblePosition= position_id - listView.getFirstVisiblePosition();
ViewrowView= listView.getChildAt(visiblePosition);
if (rowView != null) {
   ViewHolderholder= (ViewHolder) rowView.getTag();
   holder.badge.show();
} else {
   //Sorry the row is not visible
}

UPDATE: this only works for visible rows If you want to change the badge for rows that are not visible you should consider to store the ViewHolders in a list in the adapter and accessing them from there.

Post a Comment for "Update Adapter From Different Method"