Android 如何在可展开的ListView中将xml布局作为子项添加
我想将XML布局(用于执行表单提交)添加为可扩展listview中的子项。我无法使用arraylist添加。请帮帮我。提前谢谢。。这是我的主要活动 公共类MainActivity扩展了ExpandableListActivity实现 OnChildClickListener{Android 如何在可展开的ListView中将xml布局作为子项添加,android,xml,expandablelistview,Android,Xml,Expandablelistview,我想将XML布局(用于执行表单提交)添加为可扩展listview中的子项。我无法使用arraylist添加。请帮帮我。提前谢谢。。这是我的主要活动 公共类MainActivity扩展了ExpandableListActivity实现 OnChildClickListener{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Expanda
@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;
}
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
ExpandableListView expandbleLis=getExpandableListView();
可膨胀的;可膨胀的;可膨胀的;可膨胀的;
expandbleLis.setGroupIndicator(空);
expandbleLis.setClickable(真);
setGroupData();
setChildGroupData();
NewAdapter mNewAdapter=新的NewAdapter(groupItem,childItem);
mNewAdapter
.充气机(
(LayoutFlater)getSystemService(上下文布局\充气器\服务),
这),;
getExpandableListView().setAdapter(mNewAdapter);
expandbleLis.setOnChildClickListener(这个);
}
public void setGroupData(){
集团项目。添加(“abcd”);
集团项目。添加(“efgh”);
}
ArrayList groupItem=新的ArrayList();
ArrayList childItem=新的ArrayList();
public void setChildGroupData(){
/**
*添加第一个子项
*/
ArrayList子项=新的ArrayList();
添加(“Java”);
添加(“Drupal”);
添加(子项);
/**
*添加第二个子项(这里我想添加一个xml布局作为表单提交目的的子项)
*/
child=newarraylist();
添加(“安卓”);
添加(“黑莓”);
添加(子项);
}
@凌驾
公共布尔onChildClick(ExpandableListView父视图,视图v,
int groupPosition、int childPosition、long id){
Toast.makeText(MainActivity.this,“单击子对象”,
吐司。长度(短)。show();
返回true;
}
}