Well, you can use this to go from identifier-as-a-string to
identifier-as-a-number:

http://developer.android.com/reference/android/content/res/Resources.html#getIdentifier(java.lang.String,
java.lang.String, java.lang.String)

Another option is to specify tags for your buttons with
android:tag="blahblahblah" in the XML, and then use
View.findViewWithTag:

http://developer.android.com/reference/android/view/View.html#findViewWithTag(java.lang.Object)

I understand that neither option is very fast, so use carefully (cache
the results in a more directly accessible data structure).

-- Kostya

20 марта 2012 г. 20:08 пользователь Bozzified <[email protected]> написал:
> Oh, yeah I can do that. I can do manual check and target specifically radio
> buttons I need with switch.
>
> What I"m trying to do is target specific instances of RadioButton class in
> this case based on my XML input I got from CMS and the choices users set in
> it. For example what radio buttons will show and which ones wont'.
>
> I"m trying to make 1 simply method that will look like this:
>
> private void turnRadiosOnOff(int radioButtonID){
>    // and then I would target a specific radio button based on the ID passed
> into this method like this:
>    RadioButton radioInstance = getRadioChild("_radio"+id);
> }
>
> So in my layout I would have all radio buttons defined but code would hide
> them all with GONE and then I would just reveal the ones they selected in
> the XML file by using this one simple method above by passing a simple ID.
>
> Hope that make sense.
>
>
>
> On Tuesday, March 20, 2012 7:50:51 AM UTC-7, MagouyaWare wrote:
>>
>> Why can't you do something like this:
>>
>> public class A extends Activity
>> {
>>       private RadiotButton _radio1;
>>
>>       protected void onCreate(Bundle bundle)
>>       {
>>             setContentView(your.layout.id)
>>             _radio1 = findViewById(R.id.RadioButton01);
>>       }
>>
>>       public void doSomethingLater()
>>       {
>>            //Do something here with the radio button...
>>             _radio1.setChecked(true);
>>       }
>> }
>>
>> Thanks,
>> Justin Anderson
>> MagouyaWare Developer
>> http://sites.google.com/site/magouyaware
>>
>>
>> On Mon, Mar 19, 2012 at 8:19 PM, Bozzified <[email protected]> wrote:
>>>
>>> Sorry if it's a rudimentary question about Java as I'm coming from AS3
>>> and just basically starting out. Though I understand many concepts so far
>>> and am writing my first app I'm trying to find best practices in some cases.
>>>
>>> My question is the following.
>>>
>>> In AS3, I could I address an instance of a class with the string.
>>>
>>> So in AS3, I could do this:
>>>
>>> var myMC = new MovieClip();
>>>
>>> myMC.name = "somename";
>>>
>>>
>>> now in my other code I can do this
>>>
>>> var tmpInstance = this.getChildByName("somename");
>>>
>>>
>>>
>>> Is there an equivalent like this in Java/Android dev?
>>>
>>> So for a super simple example.. I'm writing a code now that looks like
>>> this:
>>>
>>> RadioButton myRadioBttn1 = findViewById(R.id.RadioButton01);
>>> RadioButton myRadioBttn2 = findViewById(R.id.RadioButton01);
>>>
>>>
>>> but later in the or in my custom methods I want to do something like
>>> this:
>>>
>>> RadioButton myRadioBttn1_instance = this.getRadioButton("myRadioBttn1");
>>>
>>> where i"m really just coming out with my own syntax here to get my point
>>> across. So I am trying to address a specific instance of the class I defined
>>> earlier in the code by passing a specific string so I can do something
>>> dynamically in the code.
>>>
>>> I am sure I'm looking at this completely the wrong way as it is not done
>>> like that (I'm sure that it's a bad practices because in my example I'm
>>> creating a new instance rather than working on the existing one) but I'm not
>>> sure how to do this dynamically.
>>>
>>> Thanks.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to