findViewById -observation for dynamic Views (not created using layout file)

by priyanka » Mon, 12 Apr 2010 15:59:26 GMT


Sponsored Links
 This is an observation I made while using findViewById() for views
which I had made dynamically(they were not in a layout file). I had
made these views in onCreate() of Activity, and set their top-level
parent view as the content of the Activity thorugh setContentView()
within the onCreate() method.

When I tried to search a view by parentView.findViewById(id), I
sometimes got null. But whenever I tried to search them through
activity.findViewById(id) - I was always able to get the View object.
I was earlier assuming parentView.findViewById(id) should always
return the child View - however, perhaps the fact that these Views are
not created through a layout file is causing these quirks.

Just posting it here, for the benefit of others who may be trying to
find a  dynamic view by its Id. If anybody has had other experiences
in this regard, please let me know.

Thanks,
Priyanka

--



Other Threads

1. How to use the dpad button to pause and play audio while the device is locked

The headset button is handled specially




> 

2. Select image resource dynamically

Hi all,

I'm facing a problem,

I've added a folder of 350 images representing country flags in my
project

according the device country given by locale. Let's say fr for France

I would like set an image with fr.png which is in the res/drawable
folder. How to achieve this without maintaining an ugly map in the
code saying fr = R.drawable.fr etc etc .

Thank you for your help.

Croco

-- 

3. Upgrade official Magic

4. Wipe?

5. Req - fbabble & andfbchat

6. Paging Bos 9b

7. Paging boss florentinus