Is there a way to get the text from a checked radiobutton from a radiogroup?
I have a static radiogroup in my XML layout, but I have created all of the radiobuttons dynamically as an effect of user input. Since none of these have ID's, is there a way I can call a method on a whole radiogroup to just return the text (or label) of the checked radio button? All the labels are URL's so if I can get 开发者_StackOverflow中文版the URL of the checked radio button then I can pass it to a method i created to open the web browser.
I can use ID's but then I would have to create a bunch of extra text for the radio button labels anyways, then a bunch of if statements with the labels written a second time.. [ if this ID is selected go to this URL, if this ID is open go to this URL...] Where as I just want to take the RadioButton's label and just put it right into the browser method.
I found this post: Android: How to get text of dynamically created radio button selected by the user?
but it wasn't answered correctly.
Thanks in advance.
If IDs are no good for you, maybe you should use the tag property that all Views have, i.e. call radioButton.setTag(url)
when you create the button. Then call View.getTag()
in your onClickListener and cast to a String
to get your URL back.
精彩评论