gpt4 book ai didi

android - 将 ListView 更改为 ExpandableListView

转载 作者:行者123 更新时间:2023-11-30 03:24:24 26 4
gpt4 key购买 nike

我的 Activity 中有一个 ListView,但现在我想将其更改为 ExpandableListView。我是否需要完全更改我的 ListView ,或者我可以将 expandableListView 添加到我现有的 ListView 中?

最佳答案

这是我使用的示例。您可以更改它并使用它。

// ListView 代码

public class FevList extends ExpandableListActivity {
String title;
String url;
SQLiteDatabase database;
DbUtil db;
HashMap<String, String> map = new HashMap<String, String>();
ArrayList<HashMap<String, String>> subjectList = new ArrayList<HashMap<String, String>>();


@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(R.layout.exlist);
db = new DbUtil();
database = db.openConnection(this);
// Thread for getting values of title from DataBase.
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this, createGroupList(), R.layout.group_row,
new String[] { "subject" }, new int[] { R.id.row_name },
createChildList(), R.layout.child_row,
new String[] { "title" }, new int[] { R.id.grp_child });
setListAdapter(expListAdapter);
registerForContextMenu(getExpandableListView());
} catch (Exception e) {
e.printStackTrace();
}

}



// code for adapter



/* Creating the Hashmap for the row */
ArrayList<HashMap<String, String>> result = new ArrayList<HashMap<String, String>>();

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

// write your code here.

return (List) result;

}

/* creatin the HashMap for the children */

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

// write your code here.
return result;
}

public void onContentChanged() {

System.out.println("onContentChanged");

super.onContentChanged();

}

/* This function is called on each child click */

public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {

// write your code here.

return true;

}

/* This function is called on expansion of the group */

public void onGroupExpand(int groupPosition) {

try {

System.out.println("Group exapanding Listener => groupPosition = "
+ groupPosition);

} catch (Exception e) {

System.out.println(" groupPosition Errrr +++ " + e.getMessage());

}

}
}

关于android - 将 ListView 更改为 ExpandableListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18510291/

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