简体   繁体   English

来自解析的JSON数组的listview中的自定义标头

[英]Custom Header in listview from parsed JSON Array

I am showing JSON data in listview. 我在列表视图中显示JSON数据。 I am parsing JSON array and getting 3 values. 我正在解析JSON数组并获取3个值。

  1. time , is in format (8/1/2013 12:30:00 PM) 时间,格式为(8/1/2013 12:30:00 PM)
  2. place , is in string format place,为字符串格式
  3. address , is in string format address,为字符串格式

Now I want to show header as those event are on 8/1/2013 are shown under header name as date "8/1/2013" and those entries on different date shown under their respective section with proper date 现在,我要显示标题,因为这些事件发生在2013年8月1日,标题名称下显示为日期“ 8/1/2013”​​,而那些在不同日期的条目则在其相应部分下显示了正确的日期

Piece of my code: 我的代码片段:

ArrayList<RidesValue> alrides = new ArrayList<RidesValue>();
List<String> rides = new ArrayList<String>();
ListView listView;

 public class RidesValue
 {
    String time;
    String place;
    String address;

 }

public void displaylist(String time, String place, String address)
{
    RidesValue rideval = new RidesValue();

    rideval.time = time;
    rideval.place = place;
    rideval.address = address;

    alrides.add(rideval);

    rides.add("Time: " + time + "\nPlace: " + place
            + "\nAddress: " + address);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.simplelist, rides);

    listView = (ListView) findViewById(R.id.lvride);
    listView.setAdapter(adapter);

}

I call displaylist method every i parse a single array from json array: 我每次从json数组解析一个数组时都调用displaylist方法:

                    JSONArray jarray = new JSONArray(savedresponse);

            if(jarray.length() == 0)
                Toast.makeText(this, "Sorry no rides found",                                 Toast.LENGTH_SHORT).show();

            Log.i("JSON ARRAY",String.valueOf(jarray));

            for(int i=0; i<jarray.length(); i++)
            {
                JSONObject value = jarray.getJSONObject(i);

                time = value.getString("Time");
                place = value.getString("Place");
                address = value.getString("Address");

                displaylist(time, place,address);
            }

So question is where and how i put n what code so group entries by under date as header in list view 所以问题是我在哪里以及如何放置n什么代码,以便按日期将条目分组为列表视图中的标题

Your question was not so clear. 您的问题不清楚。 But as much I understood i think you can go for Expandable ListView. 但据我所知,我认为您可以使用Expandable ListView。

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

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