dimanche 19 avril 2015

Putting large strings of data into ExpandableListView with string-array


Problem: I want to create an ExpandableListView that when you click on a parent, it displays a child that is a stored list made in a string-array in your strings.xml file. The strings are a few sentences each.



Lots of ExpandableListView tutorials and samples online have smaller bits of data being stored. Also they are all storing them in java. That kind of sucks because what if you want to translate your app and you are handling a list of longer strings? It would be easier to have it in your strings.xml file. How would I display that data using code like that? I don't want to edit the data at all, it's going to remain static like reference material.


Like this one, I can see how it is doing it in java. http://ift.tt/1e1h4JP


It's using an arraylist in java to store and display data:



listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

// setting list adapter
expListView.setAdapter(listAdapter);
}

/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();

// Adding child data
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");

// Adding child data
List<String> top250 = new ArrayList<String>();

// Adding child data
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
top250.add("The Godfather");
top250.add("The Godfather: Part II");
top250.add("Pulp Fiction");
top250.add("The Good, the Bad and the Ugly");
top250.add("The Dark Knight");
top250.add("12 Angry Men");

List<String> nowShowing = new ArrayList<String>();
nowShowing.add("The Conjuring");
nowShowing.add("Despicable Me 2");
nowShowing.add("Turbo");
nowShowing.add("Grown Ups 2");
nowShowing.add("Red 2");
nowShowing.add("The Wolverine");

List<String> comingSoon = new ArrayList<String>();
comingSoon.add("2 Guns");
comingSoon.add("The Smurfs 2");
comingSoon.add("The Spectacular Now");
comingSoon.add("The Canyons");
comingSoon.add("Europa Report");

Aucun commentaire:

Enregistrer un commentaire