I'm creating a simple music streaming app prototype that uses an ExpandableListView to show different music categories and different radios inside.
I followed a tutorial for the code of the Expandable list and it looks like this:
public class MainActivity extends Activity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
//Detects child item click
expListView.setOnChildClickListener(new OnChildClickListener(){
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
//ends OnCreate
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Alternative");
listDataHeader.add("Ambient");
listDataHeader.add("Blues");
listDataHeader.add("Classical");
listDataHeader.add("Hip-Hop");
listDataHeader.add("Jazz");
listDataHeader.add("Rock");
listDataHeader.add("Test");
// Adding child data
List<String> Alternative = new ArrayList<String>();
Alternative.add("WTH.Alternative");
Alternative.add("This Is Corrosion");
List<String> Ambient = new ArrayList<String>();
List<String> Blues = new ArrayList<String>();
Blues.add("Belly Up 4 Blues");
List<String> Classical = new ArrayList<String>();
List<String> HipHop = new ArrayList<String>();
List<String> Jazz = new ArrayList<String>();
List<String> Rock = new ArrayList<String>();
Rock.add("SoR Radio");
Rock.add("Megarock Radio");
Rock.add("Aural Moon");
List<String> Test = new ArrayList<String>();
Test.add("Radio with Link that I know it works");
//http://usa8-vn.mixstream.net:8138
listDataChild.put(listDataHeader.get(0), Alternative); // Header, Child data
listDataChild.put(listDataHeader.get(1), Ambient);
listDataChild.put(listDataHeader.get(2), Blues);
listDataChild.put(listDataHeader.get(3), Classical);
listDataChild.put(listDataHeader.get(4), HipHop);
listDataChild.put(listDataHeader.get(5), Jazz);
listDataChild.put(listDataHeader.get(6), Rock);
listDataChild.put(listDataHeader.get(7), Test);
}
}
I'm also using an adapter class that provides the required methods to render listview.
My problem is, at this moment, when I click a child node from the Expandable list, I just Toast a message. What I want to do now is, when I click a child node I want to pass a link that I must somehow associate with that particular child to a different activity where I will stream the music from the link (every child will have a different link associated).
I already know how to use Android MediaPlayer to stream from resources, my only problem is to bind and send the information when clicking the child node of the list.
Any idea on how to do that?