gpt4 book ai didi

android - 如何在另一个线性布局的线性布局中创建可扩展 ListView

转载 作者:行者123 更新时间:2023-11-30 04:12:06 25 4
gpt4 key购买 nike

我尝试了很多次,但我不知道为什么我做不到。在我声明可扩展列表后查看:

listView =(ExpandableListView)findViewById(R.id.expandableListView1);

然后我创建我的适配器;

public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
private String[][] children = {
{ "Arnold", "Barry", "Chuck", "David" },
{ "Ace", "Bandit", "Cha-Cha", "Deuce" },
{ "Fluffy", "Snuggles" },
{ "Goldy", "Bubbles" }
};

public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}

public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}

public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}

public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);

TextView textView = new TextView(ExpandableList1.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}

public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
return textView;
}

public Object getGroup(int groupPosition) {
return groups[groupPosition];
}

public int getGroupCount() {
return groups.length;
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}

public boolean hasStableIds() {
return true;
}

}

然后我将我的适配器设置为 listView。

mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);

但是有太多的问题我无法创造;如果你帮助我,我会很高兴。谢谢。

最佳答案

除非您发布错误日志但尝试引用这些链接,否则我们找不到错误:

ExpandableListView on Android

Simple ExpandableListView Demo

Custom ExpandableListView on Android

希望对你有帮助

关于android - 如何在另一个线性布局的线性布局中创建可扩展 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10690439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com