title: How to by default Open expand Expandable Listview Groups
body: <p>Hi i am beginner in android and in my app i need to add Expandable Listview on Scrollview </p>
  
  <p>I have added and implementing functionality like below for adding ExpandableListview on Scrollview now it's working fine </p>
  
  <p>But according to my Case by default Expandable ListView groups need to expand how can i do this </p>
  
  <p>can some one help me please</p>
  
  <h2>Main.xml</h2>
  
  <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;include
              android:id="@+id/tool_bar"
              layout="@layout/toolbar_layout"&gt;
          &lt;/include&gt;
  
          &lt;ExpandableListView
              android:id="@android:id/list"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:groupIndicator="@null" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <h1>MainActivity:</h1>
  
  <pre><code>public class MainActivity extends ExpandableListActivity {
  
      ArrayList&lt;AvailableTimingsBean&gt; availableTimingsBeanArrayList;
      ExpandableListView expandableListView;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.main);
          expandableListView = (ExpandableListView) findViewById(android.R.id.list);
  
          availableTimingsBeanArrayList = new ArrayList&lt;&gt;();
          AvailableTimingsBean availableTimingsBean = new AvailableTimingsBean();
          availableTimingsBean.setFromDay("Mon");
          availableTimingsBean.setToDay("Thurs");
  
          TimingsBean timingsBean = new TimingsBean();
          timingsBean.setFromTime("10:00AM");
          timingsBean.setToTime("12:00AM");
          ArrayList&lt;TimingsBean&gt; timingsBeanArrayList = new ArrayList&lt;&gt;();
          timingsBeanArrayList.add(timingsBean);
  
          availableTimingsBean.setTimings(timingsBeanArrayList);
          availableTimingsBeanArrayList.add(availableTimingsBean);
  
          MyExpandableAdapter adapter = new MyExpandableAdapter(this,availableTimingsBeanArrayList);
          expandableListView.setAdapter(adapter);
  
          expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
              @Override
              public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                  setListViewHeight(parent,groupPosition);
                  return false;
              }
          });
      }
  
      /**
       * @param listView
       * @param group
       */
      private void setListViewHeight(ExpandableListView listView,
                                     int group) {
  
          ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
  
          int totalHeight = 0;
          int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(),
                  View.MeasureSpec.EXACTLY);
          for (int i = 0; i &lt; listAdapter.getGroupCount(); i++) {
              View groupItem = listAdapter.getGroupView(i, false, null, listView);
              groupItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
  
              totalHeight += groupItem.getMeasuredHeight();
  
              if (((listView.isGroupExpanded(i)) &amp;&amp; (i != group))
                      || ((!listView.isGroupExpanded(i)) &amp;&amp; (i == group))) {
  
                  for (int j = 0; j &lt; listAdapter.getChildrenCount(i); j++) {
  
                      View listItem = listAdapter.getChildView(i, j, false, null,
                              listView);
  
                      listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
  
                      totalHeight += listItem.getMeasuredHeight();
                  }
              }
          }
  
          ViewGroup.LayoutParams params = listView.getLayoutParams();
          int height = totalHeight
                  + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
          if (height &lt; 10)
              height = 200;
          params.height = height;
          listView.setLayoutParams(params);
          listView.requestLayout();
      }
  }
  </code></pre>
  
  <h1>Adapter:</h1>
  
  <pre><code>public class MyExpandableAdapter extends BaseExpandableListAdapter {
  
      private LayoutInflater inflater;
      private ArrayList&lt;AvailableTimingsBean&gt; availableTimingsBeanArrayList;
      private Context context;
  
      public MyExpandableAdapter(Context context, ArrayList&lt;AvailableTimingsBean&gt; availableTimingsBeanArrayList) {
  
          inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          this.context = context;
          this.availableTimingsBeanArrayList = availableTimingsBeanArrayList;
      }
  
      @Override
      public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
  
          try {
  
              System.out.println("getChildView");
  
              final TimingsBean childObj = availableTimingsBeanArrayList.
                      get(groupPosition).getTimings().get(childPosition);
  
              if (convertView == null) {
                  convertView = inflater.inflate(R.layout.adapter_available_timings_child_items_layout, null);
              }
  
              TextView fromTime = (TextView) convertView.findViewById(R.id.fromTime_id);
              TextView toTime = (TextView) convertView.findViewById(R.id.toTime_id);
              fromTime.setText(childObj.getFromTime());
              toTime.setText(childObj.getToTime());
  
              return convertView;
  
          } catch (Throwable throwable) {
              throwable.printStackTrace();
          }
          return null;
      }
  
      @Override
      public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
  
          try {
  
              System.out.println("getGroupView");
              if (convertView == null) {
                  convertView = inflater.inflate(R.layout.adapter_available_timings_header_items, null);
              }
  
              TextView fromDay = (TextView) convertView.findViewById(R.id.fromday_textview);
              TextView toDay = (TextView) convertView.findViewById(R.id.today_textview);
              fromDay.setText(availableTimingsBeanArrayList.get(groupPosition).getFromDay());
              toDay.setText(availableTimingsBeanArrayList.get(groupPosition).getToDay());
  
              return convertView;
  
          } catch (Throwable throwable) {
              throwable.printStackTrace();
          }
          return null;
      }
  
      @Override
      public Object getChild(int groupPosition, int childPosition) {
          return null;
      }
  
      @Override
      public long getChildId(int groupPosition, int childPosition) {
          return 0;
      }
  
      @Override
      public int getChildrenCount(int groupPosition) {
  
          return availableTimingsBeanArrayList.get(groupPosition).getTimings().size();
      }
  
      @Override
      public Object getGroup(int groupPosition) {
          return null;
      }
  
      @Override
      public int getGroupCount() {
          return availableTimingsBeanArrayList.size();
      }
  
      @Override
      public void onGroupCollapsed(int groupPosition) {
          super.onGroupCollapsed(groupPosition);
      }
  
      @Override
      public void onGroupExpanded(int groupPosition) {
          super.onGroupExpanded(groupPosition);
      }
  
      @Override
      public long getGroupId(int groupPosition) {
          return 0;
      }
  
      @Override
      public boolean hasStableIds() {
          return false;
      }
  
      @Override
      public boolean isChildSelectable(int groupPosition, int childPosition) {
          return false;
      }
  }
  </code></pre>