ExpandableListView - 是有条件的扩张可能吗? [英] ExpandableListView - Is conditional expansion possible?
问题描述
我有绑定到一个SQLite数据库的ExpandableListView。为简单起见,让我们假设该数据库包含两列:标题
和体
。在ExpandableListView,有一个组
每个标题
和孩子
每个相应的体
。
I have an ExpandableListView bound to a SQLite database. To simplify things, lets assume the database contains two columns: title
and body
. In the ExpandableListView, there is a group
for each title
, and a child
for each corresponding body
.
现在让事情变得更有趣,有的在SQLite数据库中的行不具有体
(即......他们只有一个标题
)。正如你所看到的,如果没有身体,那么没有理由展开组...因为孩子将是空的(即字符串体==
)。
Now to make things more interesting, some of the rows in the SQLite database do not have a body
(that is... they only have a title
). As you can see, if there is no body, then there is no reason to expand the group... because the child will be empty (i.e. String body == ""
).
我在寻找一个办法赶上这样的情况下,并跳过该集团的扩张。我不想要一个空白的孩子进行扩展。把它放在伪code,我想是这样的:
I'm searching for a way to catch a situation like this, and skip the group's expansion. I don't want a blank child to be expanded. To put it in psuedo code, I want something like this:
if (body.getText() == "") {
//DO NOT EXPAND
//DO OTHER STUFF
}
有什么建议?
推荐答案
诀窍是在OnGroupClickListener。下面code 768,16工作。把在您的ExpandableListActivity onCreate方法的结束。
The trick is in the OnGroupClickListener. The following code shoud work. Put at the end of your onCreate method for the ExpandableListActivity.
lv.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
Cursor c = mDbHelper.fetchRow(id); //Get Title & body from SQLite table
if (c.getString(Constants.bodyColumn).equals("")) {
//If the body returned from SQLite is empty, return true
return true; //True means the click HAS been handled.
}
return false; //Click has not been handled, so let Android expand here.
}
});
这篇关于ExpandableListView - 是有条件的扩张可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!