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.



Other Threads

1. sharing data between activities.

I was playing a bit with adapters cursors and activities.
Let's assume i have a cursor containing a query I've made (it doesn't
matter if it's to DB or content provider).
Now lets assume i bind some of the data (first two rows) to a list
activity. Every click on one of those items should open a new list
activity (i pass on the cursor index in the activity bundle).
Now the question is, which sharing method will be most efficient and
right from code point of view ?

1. I thought of trying to send the cursor object in the intent itself
(hoping it implemented runnable) but I'm not so sure it's that
efficient since the query may contain many rows which will need to be
parceled, and i the other intents uses only a few (say 4-5 columns of
each row) it's a real waste.

2. Thought of trying to create the array list for my other list screen
adapter and serialize it to the intent (again use serialize and intent
to pass on the data) but again i fear for efficiency penalty.

3. my last solution was to use static cursor member in my first
activity, with package permission, it will work and be relatively
efficient, but I'm not so sure regarding  memory efficiency and code
structure, i'm not fond of using static variables in any case.

Is there another sharing method that i don't know off, if two
activities share the same process and application, then they also
share memory space, then it should be easy to pass variables from one
to another, the question is what's the easiest way without
serializing ?


2. twitter and facebook api ?


is there a twitter and facebook api for android?



3. how to add gprs modem in beagle board

4. Review sony xperia x 10

5. Application as root

6. Header View height in a ListView

7. sending lists from a server to client (android