Я хочу отправить адаптеру только один элемент из моего пользовательского списка ArrayList. Когда Активность начинается, я отправляю только один элемент. Затем я хочу внедрить жестListener в свою активность, и если я обнаружу действие прокрутки вверх или вниз, я отправлю адаптеру другой элемент. Как я могу реализовать это?
У меня есть свой собственный 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, передав только один элемент, но это не сработало.