如何在可扩展ListView中将xml布局添加为子项

时间:2012-12-28 13:02:19

标签: android xml expandablelistview

我想在Expandable listview中添加XML布局(用于执行表单提交)作为子项。我无法使用arraylist添加。请帮我。在此先感谢..这是我的主要活动

公共类MainActivity扩展了ExpandableListActivity实现         OnChildClickListener {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ExpandableListView expandbleLis = getExpandableListView();
    expandbleLis.setDividerHeight(2);
    expandbleLis.setGroupIndicator(null);
    expandbleLis.setClickable(true);

    setGroupData();
    setChildGroupData();

    NewAdapter mNewAdapter = new NewAdapter(groupItem, childItem);
    mNewAdapter
            .setInflater(
                    (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),
                    this);
    getExpandableListView().setAdapter(mNewAdapter);
    expandbleLis.setOnChildClickListener(this);
}

public void setGroupData() {
    groupItem.add("abcd");
    groupItem.add("efgh");

}

ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();

public void setChildGroupData() {
    /**
     * Add first child items
     */
    ArrayList<String> child = new ArrayList<String>();
    child.add("Java");
    child.add("Drupal");
    childItem.add(child);

    /**
     * Add second child items (here I want to add a xml Layout as a child item for form submission purpose)
     */
    child = new ArrayList<String>();
    child.add("Android");
    child.add("Blackberry");
    childItem.add(child);

}

@Override
public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
    Toast.makeText(MainActivity.this, "Clicked On Child",
            Toast.LENGTH_SHORT).show();
    return true;
}

}

0 个答案:

没有答案