0

これはListViewを更新するための私のコードです

public void onReceive(Conversation newConversation, Message message) {
                LogManager.getLogger(getClass()).info("onReceive");
                Conversation conversation = null;
                ListConversationAdapter adapter = (ListConversationAdapter)listViewConversation.getAdapter();
                int size = adapter.getCount();
                LogManager.getLogger(getClass()).info("size: " + size);
                if(size > 0)
                {
                    for(int i=0;i<size;i++)
                    {
                        if(adapter.getItemId(i) == newConversation.getId())
                        {
                            conversation = (Conversation)adapter.getItem(i);
                            break;
                        }
                    }
                }

                if(conversation == null)
                {
                    adapter.addItem(newConversation);
                    LogManager.getLogger(getClass()).info("add new conversation to adapter");
                }
                LogManager.getLogger(getClass()).info("adapter.getCount(): " + adapter.getCount());
                adapter.notifyDataSetChanged();
                LogManager.getLogger(getClass()).info("notify dataset changed");
            }
        }

これは、メソッドが呼び出された後の出力結果です

onReceive
size: 0
add new conversation to adapter
adapter.getCount(): 1

LogManager.getLogger(getClass()).info("adapter.getCount(): " + adapter.getCount()); 行で停止します。そして、adapter.notifyDataSetChanged(); をロックします。私のコードで何が問題なのですか? お願い助けて!これは getView メソッドです

public View getView(int position, View convertView, ViewGroup parent) {
        Conversation conversation = conversations.get(position);
        if(conversation != null)
        {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            LinearLayout parentView = (LinearLayout) inflater.inflate(R.layout.conversation_item, null);

            TextView textViewName = (TextView)parentView.findViewById(R.id.textViewName);
            TextView textViewLastMessage = (TextView)parentView.findViewById(R.id.textViewLastMessage);

            textViewName.setText(conversation.getName());

            List<Message> messages = MessageManager.getProvider().getMessages(conversation.getId(), 0, 0);
            if(messages.size() > 0)
            {
                Message message = messages.get(messages.size() - 1);
                textViewLastMessage.setText(Emoticon.getSmiledText(message.getBody()));
            }

            LogManager.getLogger(getClass()).info("return not null view");
            return parentView;
        }
        LogManager.getLogger(getClass()).info("return null view");
        return null;
    }
4

1 に答える 1