Display Inner Items Under Certain List Item?
There is a ListView within which I have used a Dynamic Linear Layout to add inner elements. I want to display all the Specific Term wise inner data within a specific list (i.e. Onl
Solution 1:
Change your for loop to add similar items to same object , change it to
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsonObject = jArray.getJSONObject(i);
System.out.println(i);
String course = jsonObject.getString("CourseName");
String examDescription = jsonObject.getString("examDescription");
if(arrayList.contains(examDescription))) {
student_list_courses.get(arrayList
.indexOf(examDescription)).addCourses(course);
}
else{
StudentProgressReportPojo progressReportPojo = new StudentProgressReportPojo(examDescription);
progressReportPojo.addCourses(course);
arrayList.add(examDescription);
student_list_courses.add(progressReportPojo);
}
}
also you need to change
viewHolder.student_progress_report_courses.setText(student_list_courses.get(postion).getCourses().get(i));
in your getView() function to display all Courses not just getCourses().get(i))
you need to add textviews for each item getCourses returns.
something like this
for(int x=0;x<student_list_courses.get(postion).getCourses().size();x++){
LinearLayout coursesViewDynamic = (LinearLayout) inflater
.inflate(R.layout.student_progress_report_courses_listitem, parent, false);
TextView textView=(TextView) coursesViewDynamic.findViewById(R.id.student_progressreport_subject_coursename);
textView.setText(student_list_courses.get(postion)
.getCourses().get(i));
viewHolder.coursesLayout.addView(coursesViewDynamic);
}
Hope this helps.
Solution 2:
You can use GSON/ Jackson to parse your JSON objects. You will find plenty of annotations to exclude EMPTY, NULL etc. etc. in these libraries. Also they provide a much easier code to read
An example for using GSON is given here
https://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/
Post a Comment for "Display Inner Items Under Certain List Item?"