From d5e5793b62ab3489008b569d699849dbbd5c413d Mon Sep 17 00:00:00 2001 From: XingRong Dong Date: Sun, 14 Jun 2015 17:02:59 +0800 Subject: [PATCH] Update MainActivity.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在使用过程中发现了 demo 有两个漏洞:1、列表数据为0的时候出现崩溃;2、列表数据为0的情况下,下拉无法显示头部; --- .../src/com/ryg/expandable/MainActivity.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/PinnedHeaderExpandableListView/src/com/ryg/expandable/MainActivity.java b/PinnedHeaderExpandableListView/src/com/ryg/expandable/MainActivity.java index adc448e..4fc9a6d 100644 --- a/PinnedHeaderExpandableListView/src/com/ryg/expandable/MainActivity.java +++ b/PinnedHeaderExpandableListView/src/com/ryg/expandable/MainActivity.java @@ -275,9 +275,12 @@ public View getPinnedHeader() { @Override public void updatePinnedHeader(View headerView, int firstVisibleGroupPos) { - Group firstVisibleGroup = (Group) adapter.getGroup(firstVisibleGroupPos); - TextView textView = (TextView) headerView.findViewById(R.id.group); - textView.setText(firstVisibleGroup.getTitle()); + if (adapter.getGroupCount() > 0) { // 防止列表在无数据的情况崩溃 + Group firstVisibleGroup = (Group) adapter.getGroup(firstVisibleGroupPos); + TextView textView = (TextView) headerView.findViewById(R.id.group); + textView.setText(firstVisibleGroup.getTitle()); + } + } @Override @@ -286,6 +289,8 @@ public boolean giveUpTouchEvent(MotionEvent event) { View view = expandableListView.getChildAt(0); if (view != null && view.getTop() >= 0) { return true; + } else if (adapter.getGroupCount == 0) { //保证列表没有数据的情况下,头部隐藏后还能继续下拉显示出来 + return true; } } return false;