I'm not sure I follow the logic of your code, but in the first part you have:
for (int i = 0; i < length; i++)
{
JSONObject user = jsonArray.getJSONObject(i);
for (int l = 1; l <= 5; l++)
{
preference_array.add(user.getString("id").toString());
}
}
So you get the object whose index is
i
, and add 5 copies of its id field to the array. Is that what you wanted?
You would be better setting your page number first, and then use that to extract the next 5 entries, whenever the new page button gets clicked. So if page number is 0 you get the first five elements, if it's 1 you get elements 5 to 9 etc.