2

我想在可扩展列表视图中添加 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;
}

}

4

0 回答 0