Hi DW. Anyone who knows how can I achieve this? List<String> dynamic[i];
The reason why I need this is that I'm creating a dynamic list with nested lists so there's no fixed number of data the list can be, this is inside the for statement which receive the json data which is multidimention array so I want for each item in the json data create 1st the parent list then create nested list for it.

Currently it mixes data and I see that it because of this.

Recommended Answers

All 10 Replies

Why not List<List<String>> ?

Thanks but that didn't fix my problem. The issue is that the nested recycle view bring same data in the nested view.

The main recycle view which has the titles is working according but the issue is with the nested. I have the database which I retrieve the data from I retrieve title, sample text, and date it was captured.

The title becomes the parent recycle view then the sample text and date should be inside the nested recycle view. But what happens is that I have over 80 records on the database so this means I will have over 80 recycle view with it's title (works perfectly) then inside each I will have a single sample text and date as nested to the parenting title this is where the problem is.

In the nested view it just dump all the sample texts and dates as and have the same nested recycle view on all of the parenting recycle views. In short it just put all sample text and date in the nested recycle view and have same thing on all nested recycle view.

But it should only have the relevant sample text and date to each parenting recycle view.

I use a nested Json object and loop through it.

Here's my codes.

// Data model
public class datamodel{
private List<String> nestedList;
private String itemText;
private boolean isexpendable;

public datamodel(List<String> itemList, String itemText){
this.nestedList = itemList;
this.itemText = itemText;
isexpendable = false;

public void setIsexpendable(boolean isexpendable){
this.isexpendable = isexpendable;

public List<String> getNestedList(){
return nestedList;

public String getItemText(){
return itemText;

public boolean isIsexpendable(){
return isexpensable;


Here's my Json parse code

public void JsonData(String jsonString) throws JSONException{
mList = new ArrayList<>();
recyclerView = findViewById(R.id.mrw);
recyclerView.setLayoutManager(new LinearLayoutManager(this));

List<String> nestedList1 = new ArrayList<>();

JSONObject json = new JSONObject(jsonString);
JSONArray arrayData = json.getJSONArray("data");
for (int i = 0; i < arrayData.length(); i++){
JSONObject jsonDataArray = arrayData.getJSONObject(i);
String sampleText = jsonDataArray.getString("sampleText");
String title = jsonDataArray.getString("title");
String date = jsonDataArray.getString("date");


mList.add(new datamodel(nestedList1,title));
adapter = new ItemAdapter(mList);



It looks like you have just one nestedList for all of the parents. What you need is a new nestedList for each parent.

Yes, that's why I was asking about creating it dynamically as per my initial post. That way it was going to be much easier now the issue is that the JSON data is not fixed to a certain number so it will have different sizes.

How can I create it dynamically?

That's why you use Lists not an arrays. Just create a new one and keep adding members as required. This seems very simple. Am I missing something from your requirements?

How? Where based on my above code?

The problem is with the nestedList1 I tried clearing it after it execution but it just clear all and only have the last database record only.
This is my first time working with RecyclerView.

You must have a new nestedList for each parent. Having just one and re-using it is not the answer because all the parents will share the same values. Remember that the parents just have a reference to the nestedList. Re-use the list and they will all have references to the same list. Change that list's values and they will all see the same new values. This is not a problem about RecyclerView; it's just basic Java.

I'm still stuck on this.

I guess I have to find another way of displaying data other than the NesteadListview.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.