android-如何使下一个和上一个按钮展开式列表视图?

时间:2018-07-12 02:31:18

标签: android expandablelistview

expandablelistview,但是我仍然不知道如何为expandablelistview做下一个和上一个按钮。我想为onChildClick做。在setOnGroupClickListener内,我想为onChildClick创建下一个和上一个按钮。我想在setOnGroupClickListener中播放音频文件,该文件存储在Asset文件夹中。这是代码,如何制作?

 mExpandableListView = (ExpandableListView) findViewById(R.id.expanded_menu_navigation);
    mExpandableListAdapter = new ExpandableListAdapter(this, mListDataHeader, mListDataChild);
    mExpandableListView.setAdapter(mExpandableListAdapter);

    mExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            if(groupPosition==1&&childPosition==0)
            {

                try {
                    player();
                    AssetFileDescriptor descriptor = getAssets().openFd("filepath");
                    mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                    descriptor.close();
                    mediaPlayer.prepare();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else if(groupPosition==1&&childPosition==1)
            {
                try {
                    AssetFileDescriptor descriptor = getAssets().openFd("filepath");
                    mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                    descriptor.close();
                    mediaPlayer.prepare();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else if(groupPosition==1&&childPosition==2)
            {
                try {
                    AssetFileDescriptor descriptor = getAssets().openFd("filepath");
                    mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                    descriptor.close();

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
            else if(groupPosition==1&&childPosition==3)
            {

                try {

                    AssetFileDescriptor descriptor = getAssets().openFd("filepath");
                    mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                    descriptor.close();
                    mediaPlayer.prepare();

                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

mExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            switch (groupPosition){
                case 0:
                    try {

                        AssetFileDescriptor descriptor = getAssets().openFd("filepath");
                        mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                        descriptor.close();
                        mediaPlayer.prepare();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

            }
           return false;
        }
    });
}

0 个答案:

没有答案