Reputation: 265
I've been following this logic: A multiple choice list view using expansible list
and managed to create a set of checkboxes in an expandinglistview.
So it looks something like:
catList = new ArrayList<GroupHead>();
countries = new ArrayList<Country>();
//Read the XML string
//Break down the XML into parts
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builders = factory.newDocumentBuilder();
Document document = builders.parse(new InputSource(new StringReader(XMLResult)));
//optional, but recommended
//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
document.getDocumentElement().normalize();
String rootNode = document.getDocumentElement().getNodeName().toString();
if (rootNode.equals("Results"))
{
NodeList nList = document.getElementsByTagName("Result");
System.out.println("----------------------------");
GroupHead cat1 = null;
List<GroupSession> result = new ArrayList<GroupSession>();
for (int temp = 0; temp < nList.getLength(); temp++)
{
NodeList TaskTopic = null;
Element day = (Element) nList.item(temp);
String Days = day.getAttribute("Day");
//Add one header (being the PracticalTopic)
cat1 = createCategory(Days);
TaskTopic = day.getElementsByTagName("Session");
for (int j = 0; j < TaskTopic.getLength(); ++j)
{
Element option = (Element) TaskTopic.item(j);
String optionText = option.getFirstChild().getNodeValue();
//Add multiple items and set them to that list
String[] results = optionText.split(", ");
String StartTimes = results[0];
String Lab = results[1];
sessions = new ArrayList<String>
(Arrays.asList(optionText));
ArrayList<String> citiesAustralia = new ArrayList<String>(
Arrays.asList(optionText));
countries.add(new Country(Days, citiesAustralia));
GroupSession item = new GroupSession(StartTimes, Lab);
result.add(item);
cat1.setItemList(result);
}
//Add them to the arrayList
catList.add(cat1);
}
}
}
catch (Exception e)
{
e.getMessage();
}
}
else
{
Toast.makeText(MainActivity.this, "There are no group sessions available for you", Toast.LENGTH_LONG).show();
}
adapter = new CountryAdapter(this, countries);
expListView.setAdapter(adapter);
// The choice mode has been moved from list view to adapter in order
// to not extend the class ExpansibleListView
adapter.setChoiceMode(CountryAdapter.CHOICE_MODE_MULTIPLE);
// Handle the click when the user clicks an any child
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id)
{
adapter.setClicked(groupPosition, childPosition);
return false;
}
});
Now what I'd like to do is click a button and return all the selected item values. I have something like this:
for (int i = 0; i < checked.size(); i++)
{
int position = checked.keyAt(i);
if (checked.valueAt(i) != null)
selectedItems.add(checked.valueAt(i));
}
but it's not allowing me to add the checked.valueAt(i)
. I just want to be able to read all the values from the checked list, but not finding anything that can help.
My adapter is the adapter taken from the example (way too long to add in here)
Please help!
Upvotes: 0
Views: 561
Reputation: 4951
int key = 0;
for(int i = 0; i < checked.size(); i++) {
key = checked.keyAt(i);
selectedItems.add(checked.valueAt(key));
}
Source: https://stackoverflow.com/a/8006994/4193263
Upvotes: 1