1

I have this messaging project I created.

Like facebook messenger or hangouts the new data are loaded at the bottom and older data are at the top.

my app loads the top 20 latest conversation. my problem is if the user scrolls up the older data should be loaded

I have something like this

List<Conversation> conve = new ArrayList<Conversation>();
ArrayAdapter<Conversation> adapter;

declared as global in my activity

I load the top 20 latest conversation in my conve then set the adapter on create

when a new message arrive.

I have the new message into the array

this.conve.add(..);

then execute notifyDateSetChange(); for adapter to update the data. everything was fine.

for now I am stuck right now. How do I update the first elements of the adapter if the users scrolles up? how do I update my adapter to have the old conversation? any ideas about this or sample. Thanks

1
  • Here you can can add single object or collection in your conve list at index 0. this.conve.add(0, object) And after that call notifyDateSetChange(); Commented Apr 11, 2014 at 10:18

1 Answer 1

4

Use the built in method add(int index, E element); of your list to add a element at index 0. The rest of the List will be updated.

Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

List<String> list = new ArrayList<String>();
list.add("B");
list.add("C");
list.add(0,"A");
System.out.println(list);

Output: [A, B, C]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.