Example usage for android.widget ExpandableListView expandGroup

List of usage examples for android.widget ExpandableListView expandGroup

Introduction

In this page you can find the example usage for android.widget ExpandableListView expandGroup.

Prototype

public boolean expandGroup(int groupPos, boolean animate) 

Source Link

Document

Expand a group in the grouped list view

Usage

From source file:com.fastbootmobile.encore.app.fragments.SearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View root = inflater.inflate(R.layout.fragment_search, container, false);
    assert root != null;

    mLoadingBar = (ProgressBar) root.findViewById(R.id.pbLoading);

    mAdapter = new SearchAdapter();

    ExpandableListView listView = (ExpandableListView) root.findViewById(R.id.expandablelv_search);
    listView.setAdapter(mAdapter);// www .  j  a va2 s.  co m
    listView.setGroupIndicator(null);
    for (int i = 0; i < 4; i++) {
        listView.expandGroup(i, false);
    }

    listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i2, long l) {
            if (mSearchResults != null) {
                switch (i) {
                case SearchAdapter.ARTIST:
                    onArtistClick(i2, view);
                    break;

                case SearchAdapter.ALBUM:
                    onAlbumClick(i2, view);
                    break;

                case SearchAdapter.SONG:
                    onSongClick(i2);
                    break;

                case SearchAdapter.PLAYLIST:
                    onPlaylistClick(i2, view);
                    break;

                default:
                    Log.e(TAG, "Unknown child group id " + i);
                    break;
                }

                return true;
            } else {
                return false;
            }
        }
    });

    // Restore previous search results, in case we're rotating
    if (mSearchResults != null) {
        mAdapter.appendResults(mSearchResults);
        mAdapter.notifyDataSetChanged();
    }

    return root;
}