[Android] [JAVA] Can i create different list object in the for loop via /r/learnprogramming


[Android] [JAVA] Can i create different list object in the for loop

So i am programming an expandable list on android. And i want to add list items from Firebase Database. Problem is i need a different list for every loop.

So far i did this. Annnnd I am stuck…

private void prepareListData() { listDataHeader = new ArrayList<String>(); listDataChild = new HashMap<String, List<String>>(); //for loop starts here DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); final DatabaseReference q = ref.child(""); q.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Iterator<DataSnapshot> items = dataSnapshot.getChildren().iterator(); while (items.hasNext()) { DataSnapshot item = items.next(); restName = item.child("").getValue(String.class); listMVP a =new listMVP(); a.setRestName(restName); listDataHeader.add(a.getRestName()); } } @Override public void onCancelled(DatabaseError databaseError) { } }); DatabaseReference ref1 = FirebaseDatabase.getInstance().getReference(); DatabaseReference q1 = ref1.child(""); q.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Iterator<DataSnapshot> items1 = dataSnapshot.getChildren().iterator(); while (items1.hasNext()) { DataSnapshot item1 = items1.next(); yAd = item1.child("").getValue(String.class); listMVP a =new listMVP(); a.setyAd(yAd); top250.add(a.getyAd()); } } @Override public void onCancelled(DatabaseError databaseError) { } }); //for ex List<String> nowShowing = new ArrayList<String>(); nowShowing.add("smt"); nowShowing.add("smt"); nowShowing.add("smt"); listDataChild.put(listDataHeader.get(0), top250); // Header, Child data listDataChild.put(listDataHeader.get(1), nowShowing); } 

}

Submitted July 17, 2017 at 04:18AM by CreepyProgrammer
via reddit http://ift.tt/2thIJtE

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s