1
0
mirror of https://github.com/moparisthebest/Yaaic synced 2024-11-25 18:32:15 -05:00

DeckAdapter: getView(): If no conversation is available (anymore) for the requested position, return an empty TextView. Fixes #56.

This commit is contained in:
Sebastian Kaspari 2011-04-15 20:39:33 +02:00
parent 50a6047edd
commit 1e5f016012

View File

@ -32,6 +32,7 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.Gallery; import android.widget.Gallery;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
/** /**
* The adapter for the "DeckView" * The adapter for the "DeckView"
@ -187,6 +188,15 @@ public class DeckAdapter extends BaseAdapter
public View getView(int position, View convertView, ViewGroup parent) public View getView(int position, View convertView, ViewGroup parent)
{ {
Conversation conversation = getItem(position); Conversation conversation = getItem(position);
// Market stack traces prove that sometimes we get a null converstion
// because the collection changed while a view is requested for an
// item that does not exist anymore... so we just need to reply with
// some kind of view here.
if (conversation == null) {
return new TextView(parent.getContext());
}
return renderConversation(conversation, parent); return renderConversation(conversation, parent);
} }
@ -203,6 +213,7 @@ public class DeckAdapter extends BaseAdapter
list.setOnItemClickListener(MessageClickListener.getInstance()); list.setOnItemClickListener(MessageClickListener.getInstance());
MessageListAdapter adapter = conversation.getMessageListAdapter(); MessageListAdapter adapter = conversation.getMessageListAdapter();
if (adapter == null) { if (adapter == null) {
adapter = new MessageListAdapter(conversation, parent.getContext()); adapter = new MessageListAdapter(conversation, parent.getContext());
conversation.setMessageListAdapter(adapter); conversation.setMessageListAdapter(adapter);