PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 13, 2022

[FIXED] How to change the order of the messages from JSON?

 July 13, 2022     android, json, listview, messages, parsing     No comments   

Issue

I have such JSON response with messages from the server:

response: {
count: 74246,
items: [{
  id: 343194,
  body: 'Message 3',
  user_id: 123,
  from_id: 123,
  date: 1436513626,
  read_state: 1,
  out: 0
}, {
  id: 343190,
  body: 'Message 2',
  user_id: 123,
  from_id: 321,
  date: 1436513502,
  read_state: 1,
  out: 1
}, {
  id: 343187,
  body: 'Message 1',
  user_id: 123,
  from_id: 123,
  date: 1436513198,
  read_state: 1,
  out: 0
}]
}

I put it into the listview and I have such order:

  • Message 3
  • Message 2
  • Message 1

But I want to get the next order:

  • Message 1
  • Message 2
  • Message 3

So it means that the newest messages should be from the bottom to top. Probably I should build the listview from the bottom? But how? What should I do to achieve this? And sorry for my English :)


Solution

Set reverse order on ArrayList:

ArrayList<Your_Model> mList = new ArrayList<Your_Model>();

Set data in mList from JSON:

Whenever you want to get List on reverse order, put below code.

Collections.reverse(mList);

Hope it will help you.



Answered By - Hiren Patel
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing