1

我正在实现一个聊天窗口。它在 4.2 模拟器上运行良好,但在 2.3.3 模拟器上运行很奇怪。我已经实现了一个自定义Adapter扩展BaseAdapter来填充ListVIew. 正在根据要显示的消息ListView刷新列表。itemsEmulator 4.2 正在根据需要刷新列表,但在 2.3.3 上,列表会刷新最后选择的项目。这是我的getView功能的代码。

public View getView(int position, View convertView, ViewGroup parent) {
    View chatItem = convertView;
    if (chatItem == null) {
        if (position % 2 == 0) //TODO: Change it to arrayListChat.getUpdater
            chatItem = ((LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.chat_item_me, parent, false);
        else
            chatItem = ((LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.chat_item_support, parent, false);

        ChatListItemViewHolder viewHolder = new ChatListItemViewHolder();
        viewHolder.textViewChat = (TextView) chatItem.findViewById(R.id.textViewChat);
        chatItem.setTag(viewHolder);
    }

    ChatListItemViewHolder viewHolder = (ChatListItemViewHolder) chatItem.getTag();
    viewHolder.textViewChat.setText(arrayListChat.get(position).getMessage());
    return chatItem;
}

图片链接

模拟器 4.2 http://i.imgur.com/p7LpICm.png

模拟器 2.3.3 http://i.imgur.com/fxPrEdm.png

谢谢

4

0 回答 0