"data": {
"02-08-2017": [
{
"id": "5",
"description": "testestet",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_1059758282.pdf",
"categoryname": "AGM",
"category_id": "3",
"created": "2017-08-02 00:00:00"
},
{
"id": "8",
"description": "test",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_1109112346.pdf",
"categoryname": "AGM",
"category_id": "3",
"created": "2017-08-02 00:00:00"
}
],
"31-07-2017": [
{
"id": "4",
"description": "test ets",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_804913596.pdf",
"categoryname": "Safety and security",
"category_id": "4",
"created": "2017-07-31 00:00:00"
}
],
"30-07-2017": [
{
"id": "3",
"description": "AGM meetings note detail",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_1130546608.pdf",
"categoryname": "AGM",
"category_id": "3",
"created": "2017-07-30 00:00:00"
}
],
"30-06-2017": [
{
"id": "6",
"description": "test estet",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_460968130.pdf",
"categoryname": "Safety and security",
"category_id": "4",
"created": "2017-06-30 00:00:00"
}
],
"31-05-2017": [
{
"id": "7",
"description": "test",
"file": "http:\/\/ec2-35-166-240-31.us-west-2.compute.amazonaws.com\/uploads\/building\/395009\/documents\/doc_1862829755.pdf",
"categoryname": "AGM",
"category_id": "3",
"created": "2017-05-31 00:00:00"
}
]
}
私はこのjsonオブジェクトをsectionRecyclerViewに設定していますが、各セクションの特定のキーデータだけを取得していません。sectionRecyclerviewでデータが正しく設定されていません
そして、これは私が期待mは何出力されます:私は取得mは何
private void parseJson(JSONObject data) {
if (data != null) {
Iterator<String> it = data.keys();
while (it.hasNext()) {
key = it.next();
Log.d("Key:", key);
Document document = new Document();
document.setDate(key);
try {
if (data.get(key) instanceof JSONArray) {
JSONArray arry = data.getJSONArray(key);
int size = arry.length();
for (int i = 0; i < size; i++) {
DocumentFiles files = new DocumentFiles();
JSONObject obj = arry.getJSONObject(i);
files.setFileName(obj.getString("description"));
mDocumentFiles.add(files);
document.setmList(mDocumentFiles);
Log.d("Description:",obj.getString("description"));
}
Log.d("Stop:", "Yes");
mDocumentList.add(document);
adapterDocument.addSection(new MySection(key, mDocumentList, mDocumentFiles));
} else if (data.get(key) instanceof JSONObject) {
} else {
System.out.println("" + key + " : " + data.optString(key));
}
} catch (Throwable e) {
System.out.println("" + key + " : " + data.optString(key));
e.printStackTrace();
}
}
}
adapterDocument.notifyDataSetChanged();
}
ViewHolderクラス
public class MySection extends StatelessSection {
String date;
List<Document> documentList;
List<DocumentFiles> documentFileList;
public MySection(String date, List<Document> callList, List<DocumentFiles> documentFileList) {
// call constructor with layout resources for this Section header, footer and items
super(new SectionParameters.Builder(R.layout.section_item)
.headerResourceId(R.layout.section_header)
.build());
this.date = date;
this.documentList = callList;
this.documentFileList = documentFileList;
}
@Override
public int getContentItemsTotal() {
return documentList.size(); // number of items of this section
}
@Override
public RecyclerView.ViewHolder getItemViewHolder(View view) {
// return a custom instance of ViewHolder for the items of this section
return new MyItemViewHolder(view);
}
@Override
public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
MyItemViewHolder itemHolder = (MyItemViewHolder) holder;
DocumentFiles files = documentFileList.get(position);
itemHolder.txtFile.setText(files.getFileName());
// itemHolder.txtFile.setText(documentList.get(position).getFileName());
}
@Override
public RecyclerView.ViewHolder getHeaderViewHolder(View view) {
return new MyHeaderViewHolder(view);
}
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
MyHeaderViewHolder headerHolder = (MyHeaderViewHolder) holder;
headerHolder.txtDate.setText(date);
}
class MyItemViewHolder extends RecyclerView.ViewHolder {
private final TextView txtFile;
public MyItemViewHolder(View itemView) {
super(itemView);
txtFile = (TextView) itemView.findViewById(R.id.txtFname);
}
}
class MyHeaderViewHolder extends RecyclerView.ViewHolder {
private final TextView txtDate;
public MyHeaderViewHolder(View itemView) {
super(itemView);
txtDate = (TextView) itemView.findViewById(R.id.txtDate);
}
}
}
出力がある
20-08-2017
testestet
test
31-07-2017
test ets
30-07-2017
AGM meetings note detail
30-06-2017
test
どのように私はちょうど各ヘッダーセクションにperticularイベントを設定しますか?、助けてください..ありがとう
おかげで..私は、リストオブジェクトを初期化することを忘れ仲間。 –