[android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Bozzified
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

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Justin Anderson
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 doSomethin

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Bozzified
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

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Nadeem Hasan
In your base Activity class, add this: protected RadioButton findRadioButtonById( int id ) { return (RadioButton) findViewById( id ); } This could of course throw an exception if the id does not represent a RadioButton. -- You received this message because you are subscribed to the Google

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Kostya Vasilyev
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="bl

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Lew
On Tuesday, March 20, 2012 9:25:54 AM UTC-7, Kostya Vasilyev wrote: > > 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

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Nadeem Hasan
All this is fine but OP needs to take a step back and ask himself why he needs to use a string as an identifier? In Android, numeric resource ids serve the same purpose and are already defined for you by the resource compiler. -- You received this message because you are subscribed to the Goog

Re: [android-developers] Casting string as a class (ie. RadioButton)

2012-03-20 Thread Justin Anderson
> > All this is fine but OP needs to take a step back and ask himself why he > needs to use a string as an identifier? In Android, numeric resource ids > serve the same purpose and are already defined for you by the resource > compiler. > Agreed... What I would do is create a member variable for e