繁体   English   中英

获取扩展清单视图Android的选定清单项目

[英]Get selected checklist item expanding ListView Android

我一直遵循以下逻辑: 使用可扩展列表的多选列表视图

并设法在扩展列表视图中创建了一组复选框。

所以看起来像:

    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;
    }
});

现在,我想做的是单击一个按钮并返回所有选定的项目值。 我有这样的事情:

for (int i = 0; i < checked.size(); i++) 
{
    int position = checked.keyAt(i);
    if (checked.valueAt(i) != null)
        selectedItems.add(checked.valueAt(i));
}

但是它不允许我添加checked.valueAt(i) 我只希望能够从检查的列表中读取所有值,但找不到任何可以帮助的内容。

我的适配器是示例中的适配器(太长了,无法在此处添加)

请帮忙!

int key = 0;
for(int i = 0; i < checked.size(); i++) {
   key = checked.keyAt(i);
   selectedItems.add(checked.valueAt(key));
}

资料来源: https : //stackoverflow.com/a/8006994/4193263

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM