简体   繁体   中英

Android: Listview onClick action for each item

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:

#1 FM

#2 FM

...

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.

1) Make an adapter for the list view.

2) Send 2 array lists to the adapter ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM