有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;
}
});
}