简体   繁体   English

如何在Android中更改列表视图项的顺序

[英]How to change sequence of list View items in android

I have a calendar like this: 我有这样的日历:

materialise calendar 实现日历

every tic icon shows their corresponding event. 每个tic图标都显示其相应的事件。

and I have a json response like this: 我有一个像这样的json响应:

{
    "Table": [
        {
            "userid": 4,
            "eventname": "adi",
            "eventdate": "/Date(1484121600000-0800)/",
            "eventcolor": "2413AD",
            "autoid": 2005
        },
        {
            "userid": 4,
            "eventname": "Aditya",
            "eventdate": "/Date(1479974400000-0800)/",
            "eventcolor": "5986FF",
            "autoid": 1011
        },
        {
            "userid": 4,
            "eventname": "aditya",
            "eventdate": "/Date(1484812800000-0800)/",
            "eventcolor": "13AD1A",
            "autoid": 2006
        },
        {
            "userid": 4,
            "eventname": "dfgdgdgs",
            "eventdate": "/Date(1478678400000-0800)/",
            "eventcolor": "AD3D1F",
            "autoid": 1005
        },
        {
            "userid": 4,
            "eventname": "dfgdgdgs",
            "eventdate": "/Date(1478678400000-0800)/",
            "eventcolor": "AD3D1F",
            "autoid": 1006
        }
    ]
}

Here comes the real problem.When I click any date on the calendar, above json response comes in a listView according to sequence of json. 这是真正的问题。当我单击日历上的任何日期时,上面的json响应会根据json的顺序出现在listView中。 But, I want to change the sequence according to which date i clicked(ie Date i am clicked in the calendar, that date comes first in the list and remaining item comes after that). 但是,我想根据我单击的日期更改顺序(即,我在日历中单击的日期,该日期在列表中排在第一位,其余项目在此之后)。

I'm not posting any code, If any one wants to see my code, please ask. 我没有发布任何代码,如果有人想查看我的代码,请询问。

When you parse the list from JSON at that time you check the date of each object and compare to the clicked date and store that particular index. 那时,当您从JSON解析列表时,您将检查每个对象的日期,并与单击的日期进行比较并存储该特定索引。 Then you simply parse the list from JSON response at parsing time you remove that particular object at that stored index and move to the first position of that list. 然后,您只需在解析时从JSON响应中解析列表,就可以在存储的索引处删除该特定对象,然后移至该列表的第一个位置。 Use code like: 使用如下代码:

list.removeAt(stored_index);
list.add(0, objectOfList);

and then simply add that list to adapter 然后只需将该列表添加到适配器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM