diff --git a/ExpandableHeightListViewExample/app/src/main/java/paolorotolo/github/com/expandableheightlistviewexample/ExpandableListView.java b/ExpandableHeightListViewExample/app/src/main/java/paolorotolo/github/com/expandableheightlistviewexample/ExpandableListView.java index 881d59f..ba27257 100644 --- a/ExpandableHeightListViewExample/app/src/main/java/paolorotolo/github/com/expandableheightlistviewexample/ExpandableListView.java +++ b/ExpandableHeightListViewExample/app/src/main/java/paolorotolo/github/com/expandableheightlistviewexample/ExpandableListView.java @@ -17,7 +17,10 @@ protected void onCreate(Bundle savedInstanceState) { ArrayList numbersArray = new ArrayList(); ExpandableHeightListView expandableListView = (ExpandableHeightListView) findViewById(R.id.expandable_listview); - + + // If you do not want scroll to go to the bottom of page when changed height of the listview. + expandableListView.setFocusable(false); + int i; for (i=0; i<=20; i++){ numbersArray.add(i); @@ -28,8 +31,11 @@ protected void onCreate(Bundle savedInstanceState) { expandableListView.setAdapter(itemsAdapter); + // No required. // This actually do the magic - expandableListView.setExpanded(true); + // expandableListView.setExpanded(true); + + } @Override diff --git a/README.md b/README.md index f2090cf..8d39eb7 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,6 @@ Expand ExpandableHeightListView **programmatically**: ExpandableHeightListView expandableListView = (ExpandableHeightListView) findViewById(R.id.expandable_listview); expandableListView.setAdapter(adapterName); - - // This actually does the magic - expandableListView.setExpanded(true); ``` It also works well with **GridView**. diff --git a/library/app/src/main/java/com/github/paolorotolo/expandableheightlistview/ExpandableHeightListView.java b/library/app/src/main/java/com/github/paolorotolo/expandableheightlistview/ExpandableHeightListView.java index 9cba1ab..ad1a5ba 100644 --- a/library/app/src/main/java/com/github/paolorotolo/expandableheightlistview/ExpandableHeightListView.java +++ b/library/app/src/main/java/com/github/paolorotolo/expandableheightlistview/ExpandableHeightListView.java @@ -41,4 +41,10 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { public void setExpanded(boolean expanded) { this.expanded = expanded; } -} \ No newline at end of file + // 2017.02.06 :: no need to write setExpanded method anymore + @Override + public void setAdapter(ListAdapter adapter) { + super.setAdapter(adapter); + setExpanded(true); + } +}