我在任何地方都找不到将子项添加到我的可展开列表的说明。我所能找到的就是关于如何改变背景颜色的50个问题。
现在,我使用下面的代码来创建一个普通的列表视图:
public String listArray[] = { "Example1", "Example2", "Example3", "Example4", "Example5"};
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
listV = (ListView) findViewById(R.id.exListView);
listV.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listArray));
} 但是我该如何在example1、example2等下面添加子或子项呢?
发布于 2011-06-07 22:47:35
对于初学者来说,您需要使用ExpandableListView而不是ListView。然后抛出一个SimpleExpandableListAdapter并维护对您的组(父)和子数据对象的引用。
然后它就像这样简单:
mChildData.get(groupIndex).get(childIndex).put(...);
mListAdapter.notifyDataSetChanged();发布于 2014-05-22 13:43:07
expandablelistview的基本示例是..here...
在您的活动中实现OnChildClickListener并实现此方法。
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//Add new chid data in your list (ex ArrayLis or Array whatever you use)
adapter.notifyDataSetChanged() // BaseExpandableListAdapter's adapter...
return true;
}这对你来说是工作吗?
https://stackoverflow.com/questions/6266928
复制相似问题