Zhubham wrote:
> Hi Experts,
> 
> I am trying to optimize the following code:
> 
>                           textview[0]=(TextView)findViewById
> (R.id.TextView1);
>                 textview[1]=(TextView)findViewById(R.id.TextView2);
>                 textview[2]=(TextView)findViewById(R.id.TextView3);
>                 textview[3]=(TextView)findViewById(R.id.TextView4);
>                 textview[4]=(TextView)findViewById(R.id.TextView5);
>                 textview[5]=(TextView)findViewById(R.id.TextView6);
>                 textview[6]=(TextView)findViewById(R.id.TextView7);
>                 textview[7]=(TextView)findViewById(R.id.TextView8);
>                 textview[8]=(TextView)findViewById(R.id.TextView9);
>                 textview[9]=(TextView)findViewById(R.id.TextView10);
> 
> using:
> 
> int j;
> for(int i=0;i<10;i++)
> {
>                                    j = i+1;
>                          textViewId = "TextView"+j;
>                          textview[i] = 
> (TextView)findViewById(R.id.textViewId);//
> error textViewId not recognized
> }
> 
> but this is giving error at the last line.. Can you please help me to
> come out of this.

1. There is nothing named R.id.textViewId in your layout, in all likelihood.

2. Putting things in loops does not optimize the code, from an execution
speed standpoint.

3. You cannot dynamically construct the name of a widget ID in the
manner you are trying.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!

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

Reply via email to