Example usage for android.widget ExpandableListView ExpandableListView

List of usage examples for android.widget ExpandableListView ExpandableListView

Introduction

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

Prototype

public ExpandableListView(Context context) 

Source Link

Usage

From source file:at.wada811.app.fragment.ExpandableListFragment.java

/**
 * Provide default implementation to return a expandable list view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a ExpandableListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty} that is to be shown when
 * the list is empty./*from  w w w. ja v  a2 s .  c  o m*/
 * 
 * <p>
 * If you are overriding this method with your own custom content, consider including the
 * standard layout {@link android.R.layout#list_content} in your layout file, so that you
 * continue to retain all of the standard behavior of ExpandableListFragment. In particular,
 * this is currently the only way to have the built-in indeterminant progress state be shown.
 * 
 * @param inflater The LayoutInflater object that can be used to inflate any views in the
 *        fragment,
 * @param container If non-null, this is the parent view that the fragment's UI should be
 *        attached to. The fragment should not add the view itself, but this can be used to
 *        generate the LayoutParams of the view.
 * @param savedInstanceState If non-null, this fragment is being re-constructed from a previous
 *        saved state as given here.
 * @return Return the View for the fragment's UI, or null.
 */
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final Context context = getActivity();

    final FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    final LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    final ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    final FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    final TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final ExpandableListView lv = new ExpandableListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.readboy.mathproblem.app.ExpandableListFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */// w w w  .j  a  v a2  s.  com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));
    // ------------------------------------------------------------------

    /*ExpandableListView expandableListView = (ExpandableListView) View.inflate(
                                getActivity(), R.layout.expandable_gradelist, lframe);*/ // ------------------------------------------------------------------

    ExpandableListView lv = new ExpandableListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------
    /*
            ListView lv = new ListView(getActivity());
            lv.setId(android.R.id.list);
            lv.setDrawSelectorOnTop(false);
            lframe.addView(lv, new FrameLayout.LayoutParams(
        ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));*/

    // ------------------------------------------------------------------

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));
    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}

From source file:com.github.michalbednarski.intentslab.AppComponentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FragmentActivity activity = getActivity();
    FrameLayout frameLayout = new FrameLayout(activity);
    FrameLayout.LayoutParams stretch = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    FrameLayout.LayoutParams center = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER);

    final ExpandableListView expandableListView = new ExpandableListView(activity);
    expandableListView.setAdapter(this);
    expandableListView.setOnChildClickListener(this);
    expandableListView.setLayoutParams(stretch);
    frameLayout.addView(expandableListView);

    final TextView emptyView = new TextView(activity);
    emptyView.setText(activity.getString(R.string.no_components));
    emptyView.setLayoutParams(center);/*w  w w.j a va  2  s  .  com*/
    frameLayout.addView(emptyView);

    expandableListView.setEmptyView(emptyView);

    return frameLayout;
}

From source file:com.googlecode.networklog.AppFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Context context = getActivity().getApplicationContext();

    MyLog.d("[AppFragment] onCreateView");

    if (NetworkLog.settings == null) {
        NetworkLog activity = (NetworkLog) getActivity();

        if (activity != null) {
            activity.loadSettings();/*from  w w w .  j av  a  2s.  com*/
        }
    }

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);

    TextView tv = new TextView(context);
    tv.setText(getString(R.string.app_instructions));
    layout.addView(tv);

    listView = new ExpandableListView(context);
    listView.setAdapter(adapter);
    listView.setTextFilterEnabled(true);
    listView.setFastScrollEnabled(true);
    listView.setSmoothScrollbarEnabled(false);
    listView.setGroupIndicator(null);
    listView.setChildIndicator(null);
    listView.setDividerHeight(0);
    listView.setChildDivider(getResources().getDrawable(R.color.transparent));
    layout.addView(listView);

    listView.setOnGroupExpandListener(new OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            ((GroupItem) adapter.getGroup(groupPosition)).isExpanded = true;
        }
    });

    listView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
        @Override
        public void onGroupCollapse(int groupPosition) {
            ((GroupItem) adapter.getGroup(groupPosition)).isExpanded = false;
        }
    });

    listView.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            GroupItem group = (GroupItem) adapter.getGroup(groupPosition);
            ChildItem child = (ChildItem) adapter.getChild(groupPosition, childPosition);

            getActivity()
                    .startActivity(new Intent(getActivity().getApplicationContext(), AppTimelineGraph.class)
                            .putExtra("app_uid", group.app.uid).putExtra("src_addr", child.receivedAddress)
                            .putExtra("src_port", child.receivedPort).putExtra("dst_addr", child.sentAddress)
                            .putExtra("dst_port", child.sentPort));

            return true;
        }
    });

    registerForContextMenu(listView);

    if (gotInstalledApps == false) {
        getInstalledApps(true);
        gotInstalledApps = true;
    }

    startUpdater();

    return layout;
}

From source file:info.staticfree.android.units.Units.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ABOUT: {
        final Builder builder = new AlertDialog.Builder(this);

        builder.setTitle(R.string.dialog_about_title);
        builder.setIcon(R.drawable.icon);

        try {/*from   w  w  w.  j av a  2s.  com*/
            final WebView wv = new WebView(this);
            final InputStream is = getAssets().open("README.xhtml");
            wv.loadDataWithBaseURL("file:///android_asset/", inputStreamToString(is), "application/xhtml+xml",
                    "utf-8", null);
            wv.setBackgroundColor(0);
            builder.setView(wv);
        } catch (final IOException e) {
            builder.setMessage(R.string.err_no_load_about);
            e.printStackTrace();
        }

        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                setResult(RESULT_OK);
            }
        });
        return builder.create();
    }

    case DIALOG_ALL_UNITS: {
        final Builder b = new Builder(Units.this);
        b.setTitle(R.string.dialog_all_units_title);
        final ExpandableListView unitExpandList = new ExpandableListView(Units.this);
        unitExpandList.setId(android.R.id.list);
        final String[] groupProjection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        // any selection below will select from the grouping description
        final Cursor cursor = managedQuery(UsageEntry.CONTENT_URI_CONFORM_TOP, groupProjection, null, null,
                UnitUsageDBHelper.USAGE_SORT);

        unitExpandList.setAdapter(new UnitsExpandableListAdapter(cursor, this,
                android.R.layout.simple_expandable_list_item_1, android.R.layout.simple_expandable_list_item_1,
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 },
                new String[] { UsageEntry._UNIT }, new int[] { android.R.id.text1 }));
        unitExpandList.setCacheColorHint(0);
        unitExpandList.setOnChildClickListener(allUnitChildClickListener);
        b.setView(unitExpandList);
        return b.create();
    }

    case DIALOG_UNIT_CATEGORY: {
        final Builder b = new Builder(new ContextThemeWrapper(this, android.R.style.Theme_Black));
        final String[] from = { UsageEntry._UNIT };
        final int[] to = { android.R.id.text1 };
        b.setTitle("all units");
        final String[] projection = { UsageEntry._ID, UsageEntry._UNIT, UsageEntry._FACTOR_FPRINT };
        final Cursor c = managedQuery(UsageEntry.CONTENT_URI, projection, null, null,
                UnitUsageDBHelper.USAGE_SORT);
        dialogUnitCategoryList = new SimpleCursorAdapter(this, android.R.layout.select_dialog_item, c, from,
                to);
        b.setAdapter(dialogUnitCategoryList, dialogUnitCategoryOnClickListener);

        return b.create();
    }

    case DIALOG_LOADING_UNITS: {
        final ProgressDialog pd = new ProgressDialog(this);
        pd.setIndeterminate(true);
        pd.setTitle(R.string.app_name);
        pd.setMessage(getText(R.string.dialog_loading_units));
        return pd;
    }

    default:
        throw new IllegalArgumentException("Unknown dialog ID:" + id);
    }
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

private void initBookmarkDropdown() {
    if (mBookmarksList == null)
        mBookmarksList = new ExpandableListView(this);
    if (findViewById(R.id.list_frag) != null) {
        ViewGroup leftNav = ((ViewGroup) findViewById(R.id.list_frag));
        leftNav.removeAllViews();//  w ww. jav  a 2 s .c om
        leftNav.addView(mBookmarksList);
    } else {
        View anchor = null;
        if (anchor == null)
            anchor = findViewById(R.id.title_icon);
        if (anchor == null)
            anchor = findViewById(android.R.id.home);
        if (anchor == null && USE_ACTION_BAR && !BEFORE_HONEYCOMB && getActionBar() != null
                && getActionBar().getCustomView() != null)
            anchor = getActionBar().getCustomView();
        if (anchor == null)
            anchor = findViewById(R.id.title_bar);
        if (anchor == null)
            anchor = findViewById(R.id.base_bar);
        if (anchor == null)
            anchor = findViewById(R.id.base_row);
        mBookmarksPopup = new BetterPopupWindow(this, anchor);
        mBookmarksPopup.setContentView(mBookmarksList);
    }
    mBookmarks = new OpenBookmarks(this, mBookmarksList);
    for (int i = 0; i < mBookmarksList.getCount(); i++)
        mBookmarksList.expandGroup(i);
}