gpt4 book ai didi

java - 如何在 Android 的 ExpandableListView 中为不同的父列表添加不同的子列表?

转载 作者:行者123 更新时间:2023-12-01 05:14:34 24 4
gpt4 key购买 nike

我正在使用 ExpandableListView 来获取可扩展列表。我有 3 个可扩展的“父”列表:价格、详细信息、注释。我希望能够为每个父列表添加唯一的子列表。但按照现在的设置方式,为每个父列表添加相同的子列表。如何制作才能为价格、详细信息和注释添加唯一的、单独的子列表?

这是我的代码:

public class Assignment extends ExpandableListActivity {

int listFlag = 0;

@SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_assignment);

SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.

}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}


//Create Headings of Assignment attributes
private List createGroupList() {
ArrayList result = new ArrayList();

//Create string array for Topic headings
String[] topics = {"Price", "Details", "Notes"};

//Iterate through array of names to lay them out correctly
for( int i = 0 ; i < 3 ; ++i ) {
listFlag = i;
HashMap m = new HashMap();
m.put( "Group Item", topics[i] ); // the key and it's value.
result.add( m );
}
return (List)result;

}

@SuppressWarnings("unchecked")
private List createChildList() {

ArrayList result = new ArrayList();
for( int i = 0 ; i < 3 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 1 ; n++ ) {
HashMap child = new HashMap();
child.put( "Sub Item", " "test"));
secList.add( child );
}
result.add( secList );
}
return result;
}

最佳答案

Android 不支持嵌套 ListView 。

关于java - 如何在 Android 的 ExpandableListView 中为不同的父列表添加不同的子列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11458214/

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