Listview implements the processing of different data items in the chat list
Usually, the layout of each item in the listview we are used to is the same, but the data bound by the control is different. But this alone can not meet some of our special needs, such as our common QQ and wechat chat lists. In addition to the left and right, the content is very different, including text, voice, pictures, videos, etc. can they really be realized by listview? The answer is yes, as long as we make a type difference.
The results are as follows:
Don't care about the layout. It's free here for convenience. As you can see, there are two layouts, one is on the left and the other is on the right. Although this is a simple situation, we only need to understand the principle. No matter how complex the situation is, it can be easily solved. We only need to divide each layout into one type and load different layouts in our customized adapter according to the type we distinguish. The code is as follows:
Is it easy to find? Finally, I'll post all the code together.
item_ chat_ left.xml
item_ chat_ right.xml
activity_ chat.xml
ChatItemBean.java
ChatLVAdapter.java
ChatActivity.java
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.