Example usage for android.widget ExpandableListView setOnChildClickListener

List of usage examples for android.widget ExpandableListView setOnChildClickListener

Introduction

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

Prototype

public void setOnChildClickListener(OnChildClickListener onChildClickListener) 

Source Link

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);//from  w ww  . j a v  a  2s  .c o 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;
}

From source file:org.mifos.androidclient.main.CollectionSheetActivity.java

protected void updateContent(CollectionSheetData collectionSheet) {
    if (collectionSheet != null) {
        mCollectionSheetData = collectionSheet;

        TextView textView = (TextView) findViewById(R.id.collectionSheet_centerInfo);
        textView.setText("  + " + mCenter.getDisplayName());
        textView.setOnTouchListener(this);

        if (CollectionSheetHolder.getCollectionSheetData() == null) {
            mCollectionSheetData = collectionSheet;
        } else {//w w w  .  java2s .  c  o  m
            mCollectionSheetData = CollectionSheetHolder.getCollectionSheetData();
        }

        mSelectedCustomer = CollectionSheetHolder.getCurrentCustomer();
        if (mSelectedCustomer != null) {
            updateCustomers(collectionSheet);
        }

        if (collectionSheet.getCollectionSheetCustomer() != null
                && collectionSheet.getCollectionSheetCustomer().size() > 0) {

            ExpandableListView expandableListView = (ExpandableListView) findViewById(
                    R.id.collectionSheet_entries);
            CollectionSheetExpandableListAdapter adapter = new CollectionSheetExpandableListAdapter(
                    mCollectionSheetData, this);
            expandableListView.setAdapter(adapter);
            expandableListView.setOnItemLongClickListener(this);
            expandableListView.setOnChildClickListener(this);
            ArrayList<SaveCollectionSheetCustomer> saveCollectionSheetCustomers = new ArrayList<SaveCollectionSheetCustomer>();
            prepareSaveCollectionSheet(saveCollectionSheetCustomers);
            CollectionSheetHolder.getSaveCollectionSheet();
            mSaveCustomer.setSaveCollectionSheetCustomers(saveCollectionSheetCustomers);
            CollectionSheetHolder.setSaveCollectionSheet(mSaveCustomer);
            CollectionSheetHolder.setCollectionSheetData(mCollectionSheetData);
        }
    }

}

From source file:com.robandjen.comicsapp.FullscreenActivity.java

boolean setComicsXml(InputStream is) {
    try {//from   www .  ja v  a2s  . c o m
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new BufferedInputStream(is), null);
        mComicList = ComicsParser.parse(parser);
    } catch (Exception e) {
        return false;
    }

    //Reset to beginning
    mCurComic = 0;

    if (mComicList != null) {
        ExpandableListView elv = (ExpandableListView) findViewById(R.id.comic_drawer);
        mAdapter = new ExpandableComicListAdapter(this, mComicList);
        elv.setAdapter(mAdapter);
        elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                    long id) {
                mCurComic = mAdapter.childToComicsPos(groupPosition, childPosition);
                showCurrentComic();
                mDrawerLayout.closeDrawers();
                return true;
            }
        });
    }

    return true;
}

From source file:com.ymt.demo1.plates.hub.FireHubMainFragment.java

protected void initView(View view) {
    //??/*from  w ww.java2  s.  c  o m*/
    ExpandableListView expandableListView = (ExpandableListView) view.findViewById(R.id.hub_list_view);
    //?
    ProgressBar progressBar = new ProgressBar(getActivity());
    progressBar.setIndeterminate(true);
    expandableListView.setEmptyView(progressBar);

    hubPlateAdapter = new HubPlateAdapter(getActivity());
    expandableListView.setAdapter(hubPlateAdapter);

    //item
    expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            //???
            Intent intent = new Intent(getActivity(), SubjectsActivity.class);
            intent.putExtra("plate", childList.get(groupPosition).get(childPosition));
            intent.putExtra("group_name", parentList.get(groupPosition).getName());
            startActivity(intent);
            getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                    android.R.anim.slide_out_right);
            return true;
        }
    });

    ImageView doPostView = (ImageView) view.findViewById(R.id.hub_act_post);
    //        ImageView topPostView = (ImageView) view.findViewById(R.id.hub_act_top);
    ImageView newPostView = (ImageView) view.findViewById(R.id.hub_act_new);
    ImageView hotPostView = (ImageView) view.findViewById(R.id.hub_act_hot);
    ImageView myPostView = (ImageView) view.findViewById(R.id.hub_act_my);

    View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.hub_act_post: //?
                Intent intent1 = new Intent(getActivity(), DoPostActivity.class);
                ArrayList<HubPlate> parents = new ArrayList<>();
                for (HubPlate plate : parentList) {
                    parents.add(plate);
                }
                ArrayList<HubPlate> childs = new ArrayList<>();
                for (List<HubPlate> pList : childList) {
                    for (HubPlate plate : pList) {
                        childs.add(plate);
                    }
                }
                intent1.putParcelableArrayListExtra("parent", parents);
                intent1.putParcelableArrayListExtra("child", childs);
                getActivity().startActivity(intent1);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            //                    case R.id.hub_act_top:                                          //??
            //
            //                        break;
            case R.id.hub_act_new: //?
                Intent intentN = new Intent(getActivity(), HotNewPostActivity.class);
                intentN.putExtra("type", HotNewPostActivity.TYPE_NEW);
                startActivity(intentN);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            case R.id.hub_act_hot: //?
                Intent intentH = new Intent(getActivity(), HotNewPostActivity.class);
                intentH.putExtra("type", HotNewPostActivity.TYPE_HOT);
                startActivity(intentH);
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            case R.id.hub_act_my: //?
                startActivity(new Intent(getActivity(), MyHubTabActivity.class));
                getActivity().overridePendingTransition(android.R.anim.slide_in_left,
                        android.R.anim.slide_out_right);
                break;
            }
        }
    };
    doPostView.setOnClickListener(onClickListener);
    //        topPostView.setOnClickListener(onClickListener);
    newPostView.setOnClickListener(onClickListener);
    hotPostView.setOnClickListener(onClickListener);
    myPostView.setOnClickListener(onClickListener);

}

From source file:org.videolan.vlc.gui.audio.AudioBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.audio_browser, container, false);

    mFlingViewGroup = (FlingViewGroup) v.findViewById(R.id.content);
    mFlingViewGroup.setOnViewSwitchedListener(mViewSwitchListener);

    mHeader = (HorizontalScrollView) v.findViewById(R.id.header);
    mHeader.setOnTouchListener(new OnTouchListener() {
        @Override//from   www .  j ava  2 s .c  o m
        public boolean onTouch(View v, MotionEvent e) {
            // prevent the user from scrolling the header
            return true;
        }
    });

    ListView songsList = (ListView) v.findViewById(R.id.songs_list);
    ExpandableListView artistList = (ExpandableListView) v.findViewById(R.id.artists_list);
    ExpandableListView albumList = (ExpandableListView) v.findViewById(R.id.albums_list);
    ExpandableListView genreList = (ExpandableListView) v.findViewById(R.id.genres_list);

    songsList.setAdapter(mSongsAdapter);
    artistList.setAdapter(mArtistsAdapter);
    albumList.setAdapter(mAlbumsAdapter);
    genreList.setAdapter(mGenresAdapter);

    songsList.setOnItemClickListener(songListener);
    artistList.setOnGroupClickListener(playlistListener);
    albumList.setOnGroupClickListener(playlistListener);
    genreList.setOnGroupClickListener(playlistListener);

    artistList.setOnChildClickListener(playlistChildListener);
    albumList.setOnChildClickListener(playlistChildListener);
    genreList.setOnChildClickListener(playlistChildListener);

    registerForContextMenu(songsList);
    registerForContextMenu(artistList);
    registerForContextMenu(albumList);
    registerForContextMenu(genreList);

    return v;
}

From source file:com.arcusapp.soundbox.fragment.ArtistsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_artists, container, false);

    ExpandableListView myExpandableList = (ExpandableListView) rootView
            .findViewById(R.id.expandableListArtists);
    myExpandableList.setGroupIndicator(null);

    myExpandableList.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override//from   w w w.j a  v a2  s  .c  om
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                int groupPosition = ExpandableListView.getPackedPositionGroup(id);
                myAdapter.onArtistLongClick(groupPosition);
                return true;
            } else if (ExpandableListView
                    .getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                int groupPosition = ExpandableListView.getPackedPositionGroup(id);
                int childPosition = ExpandableListView.getPackedPositionChild(id);
                myAdapter.onAlbumLongClick(groupPosition, childPosition);
                return true;
            }
            return false;
        }
    });

    myExpandableList.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            myAdapter.onAlbumClick(groupPosition, childPosition);
            return false;
        }
    });

    myExpandableList.setAdapter(myAdapter);
    return rootView;
}

From source file:com.fitme.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.options, menu);
    MenuItem mi = menu.findItem(R.id.menu_spinner_active_program);
    final TextView tv = (TextView) mi.getActionView();
    ActiveProgramDAO apd = new ActiveProgramDAO(MainActivity.this);
    activeProgram = apd.getActiveProgramName();
    tv.setText(activeProgram);/*from w w w.  j av  a 2 s .  com*/

    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setTitle(getText(R.string.title_select_prog_dialog));
            View programView = getLayoutInflater().inflate(R.layout.programs_list, null);
            ExpandableListView elv = (ExpandableListView) programView.findViewById(R.id.list_programs);
            final ProgramListAdapter pda = new ProgramListAdapter(MainActivity.this);
            elv.setAdapter(pda);
            // Setting listener for Add Program button
            Button addProgram = (Button) programView.findViewById(R.id.button_add_program);
            addProgram.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    onAddProgramRequested(pda);
                }
            });
            elv.setGroupIndicator(null);
            elv.setOnGroupClickListener(null);
            elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition,
                        int childPosition, long l) {
                    pda.setProgramSelected(groupPosition, childPosition);
                    onNewProgramSelected(pda.getSelectedProgramName());
                    // Refresh trainings section list
                    TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter
                            .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS);
                    tsf.onNewProgramSelected();
                    dialog.dismiss();
                    return false;
                }
            });
            dialog.setContentView(programView);
            dialog.show();
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
        }
    });

    return true;
}

From source file:com.norman0406.slimgress.FragmentInventory.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_inventory, container, false);

    final ExpandableListView list = (ExpandableListView) rootView.findViewById(R.id.listView);
    final ProgressBar progress = (ProgressBar) rootView.findViewById(R.id.progressBar1);

    list.setVisibility(View.INVISIBLE);
    progress.setVisibility(View.VISIBLE);

    // create group names
    mGroupNames = new ArrayList<String>();
    mGroups = new ArrayList<Object>();

    mGroupMedia = new ArrayList<String>();
    mGroupMods = new ArrayList<String>();
    mGroupPortalKeys = new ArrayList<String>();
    mGroupPowerCubes = new ArrayList<String>();
    mGroupResonators = new ArrayList<String>();
    mGroupWeapons = new ArrayList<String>();

    final FragmentInventory thisObject = this;

    final Handler handler = new Handler();

    mGame.intGetInventory(new Handler(new Handler.Callback() {
        @Override/*from w  w  w . ja v  a  2s  . c o  m*/
        public boolean handleMessage(Message msg) {
            fillInventory(new Runnable() {
                @Override
                public void run() {
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            InventoryList inventoryList = new InventoryList(mGroupNames, mGroups);
                            inventoryList.setInflater(inflater, thisObject.getActivity());
                            list.setAdapter(inventoryList);
                            list.setOnChildClickListener(thisObject);

                            list.setVisibility(View.VISIBLE);
                            progress.setVisibility(View.INVISIBLE);
                        }
                    });
                }
            });
            return true;
        }
    }));

    return rootView;
}

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  ww .ja va2 s . c  o  m
            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.anurag.file.quest.FileQuestHD.java

private void init_drawer_menu() {
    // TODO Auto-generated method stub
    ExpandableListView drLs = (ExpandableListView) drawer.findViewById(R.id.drawer_menu_list);
    drLs.setAdapter(new drAdpt());
    drLs.setSelector(R.drawable.while_list_selector_hd);

    drLs.setOnGroupClickListener(new OnGroupClickListener() {
        @Override/*from www . j  av  a  2s  .  c om*/
        public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2, long arg3) {
            // TODO Auto-generated method stub
            switch (arg2) {
            case 0:
                Intent intent = new Intent(FileQuestHD.this, GraphAnalysis.class);
                startActivity(intent);
                break;

            case 5:
                //checks the new update for file quest....
                update_checker();
                break;
            }
            return false;
        }
    });

    drLs.setOnChildClickListener(new OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3, long arg4) {
            // TODO Auto-generated method stub
            String type = null;
            int tweakwhat = 0;
            switch (arg3) {
            case 0:
                tweakwhat = 0;
                type = " favorite ";
                break;

            case 1:
                tweakwhat = 1;
                type = " music ";
                break;

            case 2:
                tweakwhat = 2;
                type = " apps ";
                break;

            case 3:
                tweakwhat = 3;
                type = " photos ";
                break;

            case 4:
                tweakwhat = 4;
                type = " videos ";
                break;

            case 5:
                tweakwhat = 5;
                type = " documents ";
                break;

            case 6:
                tweakwhat = 6;
                type = " archives ";
                break;

            case 7:
                tweakwhat = 7;
                type = " unknown ";
                break;
            }

            new ConfirmTweakTask(FileQuestHD.this, arg2, type, tweakwhat);

            return false;
        }
    });
}