0

我只想从我的自定义 ArrayList 中向适配器发送一项。活动开始时,我只发送一项。然后我想为我的 Activity 实现gestureListener,如果我检测到向上或向下滑动动作,我会向适配器发送另一个项目。我该如何实施?

我有我的自定义 ArrayAdapter,我在其中传递了我的列表。但我只想发送一件物品:

public class InteractionsAdapter extends  ArrayAdapter<Message>{

  Context context; 
int layoutResourceId;    
List<Message> messages = null;
private Activity activity;
public InteractionsAdapter(Context context,  int layoutResourceId,List<Message> messages) {
    super(context, layoutResourceId, messages);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.messages = messages;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    InteractionHolder holder = null;

    if(row == null)
    {

        (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.interactions_item, parent, false);

        holder = new InteractionHolder();
        holder.interactionId= (TextView)row.findViewById(R.id.interactionId);
        holder.interactionAbove = (TextView)row.findViewById(R.id.interactionAbove);
        holder.interactionBelow = (TextView)row.findViewById(R.id.interactionBelow);
        holder.interactionMessage = (TextView)row.findViewById(R.id.interactionMessage);
        holder.interactionDate = (TextView)row.findViewById(R.id.interactionDate);

        row.setTag(holder);
    }
    else
    {
        holder = (InteractionHolder)row.getTag();
    }

    Message message = messages.get(position);
    Log.i("in doinbackground",Integer.toString(messages.size()));

        Log.i("position",Integer.toString(position));

        holder.interactionId.setText(Integer.toString(message.getMessageId()));
        holder.interactionAbove.setText(Integer.toString(position));
        holder.interactionBelow.setText(Integer.toString(messages.size()-position-1));
        holder.interactionMessage.setText(message.getMessageBody());
        holder.interactionDate.setText(message.getMessageDate().toString());

    return row;
}

static class InteractionHolder
{
    TextView interactionId;
    TextView interactionDate;
    TextView interactionAbove;
    TextView interactionBelow;
    TextView interactionMessage;

}

}

我试图用 ArrayAdapter 来做,只传递一项,但它不起作用。

4

1 回答 1

0

我解决了我的问题,只需添加一个

@Override
public int getCount() {
    return 1;
}

它工作正常。

于 2012-10-01T07:53:00.090 回答