how to set json data to pinned header listview

199 Views Asked by At

i'm using pinned header listview to set sticky headers on list view for that i'm using this example. but the example contains som fixed data from adapter and i want to set data which is coming from api. and my json data look like below...

"diaryEntries": [
    {
      "diaryId": "1",
      "diaryEntryType": "test",
      "studentName": "testuser",
      "diaryText": "Please learn something and come tomorrow",
      "authorName": "test author",
      "authorRole": "testRole",
      "insert_ts": "2017-09-06T08:41:11.000Z",
      "update_ts": "2017-09-06T08:41:11.000Z"
    },
    {
      "diaryId": "2",
      "diaryEntryType": "test",
      "studentName": "testuser1",
      "diaryText": "Please learn something and come tomorrow",
      "authorName": "test author1",
      "authorRole": "testRole1",
      "insert_ts": "2017-09-06T08:41:11.000Z",
      "update_ts": "2017-09-06T08:41:11.000Z"
    }
  ]

and my adapter code is from link example is

public class TestSectionedAdapter extends SectionedBaseAdapter {

    @Override
    public Object getItem(int section, int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int section, int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getSectionCount() {
        return 7;
    }

    @Override
    public int getCountForSection(int section) {
        return 15;
    }

    @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
        LinearLayout layout = null;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (LinearLayout) inflator.inflate(R.layout.list_item, null);
        } else {
            layout = (LinearLayout) convertView;
        }
        ((TextView) layout.findViewById(R.id.textItem)).setText("Section " + section + " Item " + position);
        return layout;
    }

    @Override
    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
        LinearLayout layout = null;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (LinearLayout) inflator.inflate(R.layout.header_item, null);
        } else {
            layout = (LinearLayout) convertView;
        }
        ((TextView) layout.findViewById(R.id.textItem)).setText("Header for section " + section);
        return layout;
    }

}

how to set json data in to pinned header list view and the headers are the "update_ts" from json object of list, can anyone help me to solve this?

0

There are 0 best solutions below