Reputation: 5
I'm creating an internet radio app. It has a list of stations that could be played when onClick on the item. For example
The list:
...
The thing is every item (station) has a different URL and I would not want it to be visible to the user. How can I implement it such that when click on the item, it plays the correct station? Kind of like a different onClick for each item in the list.
Upvotes: 0
Views: 506
Reputation: 5973
1) Make an adapter for the list view.
2) Send 2 array lists to the adapter i.e i) name of station ii) url of station
3) while inflating items in your list view show the name from your i) name of station array list
4) when user clicks the an item in list view get the item number clicked and find the url from your ii) url of station array list and make a network call to that url
Example - there are 3 stations named 1) ONE 2) TWO 3) THREE with respective urls 1) urlONE 2) urlTWO 3) urlTHREE
array list (call it stationList or something) will have the names of stations
array list (call it stationUrlList or something) will have the urls of stations
pass both to the adapter of list view. List 1 with names will be used to show the stations name.. When the user clicks say item 2 in the list look for the 2nd item in stationUrlList and make a network call to that Url .. i hope it helps .
Upvotes: 1