On Mon, Aug 2, 2010 at 12:11 PM, Sebastián Treu <[email protected]>wrote:
> I have read from many sources that findViewById() is a "costly" operation.
>
What sources? Define "costly". Sounds like premature optimization. I haven't
looked at the source, but I can't imaging findViewById() does much worse
than a breadth-first search down the view hierarchy. To find 5 views, unless
your hierarchy is absurd in complexity, I can't imagine this being that
"costly".
> Is it right to populate the Activity with private members of
> the Views/Layout it displays?
>
"Right" is arguable. Does it work? Then it's "right" for most accounts and
purposes.
> I mean, I don't like it.
>
Then don't do it.
> I don't know why, but seems that I'm populating too much the activity.
>
If you don't like that approach, but still want to cache the references, you
could make another class that has nothing but these references and use that.
class Data
{
public EditText Position;
... // Other stuff
}
...
// Now you have just one member
private Data mData = new Data();
...
// Initialize, use, etc
mData.Position = findViewById(...);
-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices
--
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