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. image capture and get both the original image and a thumbnail

hi
i want to take a picture with camera, after read the document and googling,I 
found,
if i don't want the original picture,i just use 

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_PICTURE_CODE);

to start the camera activity, and in  
onActivityResult(int requestCode, int resultCode,Intent intent)  method,i can 
get the thumbnail from the intent .

and if i want the original picture ,i use this 

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempImageFile()));
startActivityForResult(intent, CAPTURE_PICTURE_CODE);

to start the camera activity, 
and in onActivityResult(int requestCode, int resultCode,Intent intent) , i can 
get the original picture with 

Bitmap bm = BitmapFactory.decodeFile(getTempImageFile().getAbsolutePath());

but in this case ,the intent variable is null ,so i can't get the thumbnail.

so is there an easy way to get both the thumbnail and the original picture ?

if the only way is to use the Camera class ,and make my own camera activity ,is 
there any example code ? or is there any Camera-relative open source project ?

thanks 

-- 

2. Soft Keyboard Control

Is there a way to get the soft keyboard to come up in the same mode as
it was left the last time it was brought up.  For example, if the user
had switched to entering numbers, is there a way to set it up so that
the next time he brings up the keyboard, it will default to entering
numbers?

Failing that, is there some way to control the current input mode
(e.g. alpha or numbers) for the keyboard?

Thanks.

-- 

3. websockets in webkit

4. Checksum Java function in Android

5. Independent Wallpapers on Multiple Screens

6. how to use Opengl 2.0 on android?

7. onBind and unBind questions