gpt4 book ai didi

java - 如何让 ExpandableListView 中的 child 成为文本框而不是 Android 列表?

转载 作者:行者123 更新时间:2023-11-29 09:12:36 25 4
gpt4 key购买 nike

所以我有一个 ExpandableListView。现在我在父列表中有 3 个项目。当我单击其中一个时,子列表(弹出子列表)。我想要的是文本框显示在下方而不是列表。

我想要一个列表给 parent ,但一个文本框给 child 。我不知道该怎么做。这是我现在的代码:

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 Assignment Topic headings
String[] topics = {"1", "2", "3"};

//Iterate through array of names to lay them out correctly
for( int i = 0 ; i < 3 ; ++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 < 3 ; n++ ) {
HashMap child = new HashMap();
child.put( "Sub Item", "Sub Item " + n );
secList.add( child );
}
result.add( secList );
}
return result;
}

显然,当我希望子项成为文本框时,我正在创建一个 childList。不知道如何实现这个。非常感谢任何帮助!

最佳答案

尝试在“R.layout.child_row”中只放置一个编辑 TextView 。如果出现错误,则也放置一个 TextView ,但使其不可见。我希望这能解决问题

关于java - 如何让 ExpandableListView 中的 child 成为文本框而不是 Android 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11455726/

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