views:

67

answers:

1

Hello all,

This is probably an easy one. I have about 20 TextViews/ImageViews in my current project that I access like this:

((TextView)multiLayout.findViewById(R.id.GameBoard_Multi_Answer1_Text)).setText("");

//or

((ImageView)multiLayout.findViewById(R.id.GameBoard_Multi_Answer1_Right)).setVisibility(View.INVISIBLE);

My question is this, am I better off, from a performance standpoint, just assigning these object variables? Further, am I losing some performance to the constant "search" process that goes on as a part of the findViewById(...) method? (i.e. Does findsViewById(...) use some sort of hashtable/hashmap for look-ups or does it implement an iterative search over the view hierarchy?)

At present, my program never uses more than 2.5MB of RAM, so will assigning 20 or so more object variables drastically affect this? I don't think so, but I figured I'd ask.

Thanks.

+1  A: 

Yes, this would be correct to cache references to the views. That's what the ListView's Tag/Holder is about which is there for performance reasons.

alex