NotifyDataSetChanges for list adapter, change only part of view

This is possibly a strange question, and I understand if there will be downvotes here

So, I have a custom adapter (using the ViewHolder template) that looks like this:

    private class ViewHolder {
        ImageView chatImage;
        TextView chatName;
        TextView lastMessage;
        TextView lastMessageTime;
        TextView unreadMessagesCount;
        //ViewStub avatarsViewStub;
    }

    private ViewHolder createViewHolder (View view) {
        ViewHolder holder = new ViewHolder();
        holder.chatImage = (ImageView) view.findViewById(R.id.chat_image);
        holder.chatName = (TextView) view.findViewById(R.id.chat_participant_name);
        holder.lastMessage = (TextView) view.findViewById(R.id.last_message);
        holder.lastMessageTime = (TextView) view.findViewById(R.id.last_message_time);
        holder.unreadMessagesCount = (TextView) view.findViewById(R.id.unread_messages_count);
        return holder;
    }

TextView unreadMessagesCountshould show the number of unread messages, and whenever a new message arrives, it should be updated. But, as you can see, there is a lot Views, and my goal is here: Update only unreadMessagesCount instead of calling integers getViewwhen adapter.notifyDataSetChanges()called , I want to know if this is possible

Edit : I posted my current solution as one of the answers, but we are still looking for a more suitable approach

+4
1

ListView . , .

public View getViewByPosition(int position) {
    final int firstListItemPosition = filesListview.getFirstVisiblePosition();
    final int lastListItemPosition = firstListItemPosition + filesListview.getChildCount() - 1;
    if (position < firstListItemPosition || position > lastListItemPosition) {
        // return filesListview.getAdapter().getView(position, filesListview.getChildAt(position), filesListview);
        return null;
    } else {
        final int childIndex = position - firstListItemPosition;
        return filesListview.getChildAt(childIndex);
    }
}

ViewHolder getTag() .

View listItem = getViewByPosition(position);
if(listItem!=null){
    ViewHolder holder = (ViewHolder)view.getTag();
   //Update the data
}
0

All Articles