【发布时间】:2018-05-27 14:37:47
【问题描述】:
我有 ExpandableListView 的侦听器,用于折叠和展开组:
// There is a text view on group layout, no problem there.
@Override
public void onGroupCollapse(int groupPosition) {
// this callback is triggered, however, once the textView is BOLD by onGroupExpanded, the textView is not set back to normal, seems this line of code does nothing...WHY?
textView.setTypeface(textView.getTypeface(), Typeface.NORMAL);
}
@Override
public void onGroupExpand(int groupPosition) {
// it works fine
textView.setTypeface(textView.getTypeface(), Typeface.BOLD);
}
如您在上面看到的,我在组布局中有一个textView,当组展开时,我bold textView,如果折叠,我尝试将其设置回unboldTypeface.NORMAL。
两个回调都被正确触发,但是,一旦textView 被onGroupExpanded(...) 回调BOLD,textView 在@ 时不会被设置回NORMAL之后触发 987654329@。似乎onGroupCollapsed(...)中的代码行什么都不做......为什么?
(再次,onGroupCollapse(...) 被触发。没问题!)
【问题讨论】:
-
试试
textView.setTypeface(null, Typeface.NORMAL);它看起来怎么样? -
@donfuxx,在我进行了您建议的更改后,它现在可以工作了。但是您能否也解释一下为什么我的代码有这个问题?为什么使用 null 作为第一个参数可以解决问题?
-
我试图在我的回答中解释 ;-) 我知道 setTypeface 方法不是很直观,并且不时让自己感到困惑:-P
标签: android expandablelistview android-typeface