Example usage for android.widget ExpandableListAdapter getGroupCount

List of usage examples for android.widget ExpandableListAdapter getGroupCount

Introduction

In this page you can find the example usage for android.widget ExpandableListAdapter getGroupCount.

Prototype

int getGroupCount();

Source Link

Document

Gets the number of groups.

Usage

From source file:org.jsharkey.grouphome.LauncherActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    Intent homeIntent = new Intent();
    homeIntent.setClassName("com.android.launcher", "com.android.launcher.Launcher");
    menu.add("Default home").setIcon(R.drawable.ic_menu_home).setIntent(homeIntent);

    menu.add("Search").setIcon(android.R.drawable.ic_menu_search);

    force = menu.add("Expand all").setIcon(android.R.drawable.ic_menu_share)
            .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    ExpandableListView listView = LauncherActivity.this.getExpandableListView();
                    ExpandableListAdapter adapter = LauncherActivity.this.getExpandableListAdapter();
                    switch (expandState) {
                    case STATE_UNKNOWN:
                    case STATE_ALL_COLLAP:
                        // when unknown or collapsed, we force all open
                        for (int i = 0; i < adapter.getGroupCount(); i++)
                            listView.expandGroup(i);
                        expandState = STATE_ALL_EXPAND;
                        break;
                    case STATE_ALL_EXPAND:
                        // when expanded, we force all closed
                        for (int i = 0; i < adapter.getGroupCount(); i++)
                            listView.collapseGroup(i);
                        expandState = STATE_ALL_COLLAP;
                        break;
                    }//from  w  w  w  . j  a v  a2s.  c  o m

                    return true;
                }
            });

    menu.add("Refresh").setIcon(R.drawable.ic_menu_refresh)
            .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    // clear any database mappings and local json cache
                    // TODO: clear local json cache (when implemented)
                    appdb.deleteAllMappings();
                    setListAdapter(null);
                    new ProcessTask().execute();
                    return true;
                }
            });

    Intent settingsIntent = new Intent(android.provider.Settings.ACTION_SETTINGS);
    settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    menu.add("Settings").setIcon(android.R.drawable.ic_menu_preferences).setIntent(settingsIntent);

    return true;
}

From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java

private void setListViewHeight(ExpandableListView listView, int group) {
    ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
    if (mDefaultHeight == 0)
        mDefaultHeight = listView.getHeight();
    int totalHeight = 0;

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY);
    for (int i = 0; i < listAdapter.getGroupCount(); i++) {
        if (((listView.isGroupExpanded(i)) && (i != group))
                || ((!listView.isGroupExpanded(i)) && (i == group))) {
            for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
                View listItem = listAdapter.getChildView(i, j, false, null, listView);
                listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
                totalHeight += listItem.getMeasuredHeight();
            }// w w w . ja  va 2s .  c om
            totalHeight += mDefaultHeight;
        }
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
    if (height < mDefaultHeight)
        height = mDefaultHeight;
    params.height = height;
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:com.fortysevendeg.swipelistview.ExpandableSwipeListViewTouchListener.java

/**
 * Adds new items when adapter is modified
 *///from   www .  ja  v  a 2  s  .c o m
public void resetItems() {
    ExpandableListAdapter adp = swipeListView.getExpandableListAdapter();
    if (adp != null) {
        int count = 0;
        for (int i = 0; i < adp.getGroupCount(); i++) {
            //Add the total children and the group itself.
            count += adp.getChildrenCount(i) + 1;
        }
        System.out.println("TOTAL COUNT: " + count);
        for (int i = opened.size(); i <= count; i++) {
            opened.add(false);
            openedRight.add(false);
            checked.add(false);
        }
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

public T expand(boolean expand) {
    if (view instanceof ExpandableListView) {
        ExpandableListView elv = (ExpandableListView) view;
        ExpandableListAdapter ela = elv.getExpandableListAdapter();
        if (ela != null) {
            int count = ela.getGroupCount();
            for (int i = 0; i < count; i++) {
                if (expand) {
                    elv.expandGroup(i);/*from   w  ww.  ja v  a  2 s .c  om*/
                } else {
                    elv.collapseGroup(i);
                }
            }
        }
    }
    return self();
}

From source file:com.androidquery.AQuery.java

public AQuery expand(boolean expand) {

    if (view instanceof ExpandableListView) {

        ExpandableListView elv = (ExpandableListView) view;
        ExpandableListAdapter ela = elv.getExpandableListAdapter();

        if (ela != null) {

            int count = ela.getGroupCount();

            for (int i = 0; i < count; i++) {
                if (expand) {
                    elv.expandGroup(i);/*from   w  w  w  . ja va2s  . c om*/
                } else {
                    elv.collapseGroup(i);
                }
            }

        }

    }

    return self();
}

From source file:com.androidquery.AbstractAQuery.java

public T expand(boolean expand) {

    if (view instanceof ExpandableListView) {

        ExpandableListView elv = (ExpandableListView) view;
        ExpandableListAdapter ela = elv.getExpandableListAdapter();

        if (ela != null) {

            int count = ela.getGroupCount();

            for (int i = 0; i < count; i++) {
                if (expand) {
                    elv.expandGroup(i);/*from w  ww . j av a  2  s  .c om*/
                } else {
                    elv.collapseGroup(i);
                }
            }

        }

    }

    return self();
}