添加“孩子”或子项到 ExpandableListView
我无法在任何地方找到将子项目添加到可扩展列表中的说明。我能找到的只有 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 等下面添加子项或子项呢?
I can't find instructions to add a child item to my expandable list anywhere. All I can find is 50 questions on how to change the background color.
Right now, I am using this code to create a normal list view:
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));
}
But how would I go about adding sub or child items underneath example1, example2, etc..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于初学者,您需要使用 ExpandableListView 而不是 ListView。然后放入 SimpleExpandableListAdapter 并维护对您的组(父组)的引用和子数据对象。
然后就很简单了:
For starters, you need to use an ExpandableListView instead of a ListView. Then throw in a SimpleExpandableListAdapter and maintain a reference to your group (parent) and child data objects.
Then it's as easy as:
Expandablelistview 的基本示例是..此处.. ..
在您的 Activity 中实现 OnChildClickListener 并实现此方法。.
它对您有用吗?
Basic example for expandablelistview is.. here....
Implement OnChildClickListener in your Activity and implemet this method..
Is it work work for you?