Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the type of a view widget?

How to get that working:

 if(findViewById(ResIdWithUnkownType) instanceof Bitmap)
 {
       Bitmap bitmap = (Bitmap) findViewById(ResIdWithUnkownType);
 } else if(findViewById(ResIdWithUnkownType) instanceof ImageView)
 {
       ImageView = (ImageView) findViewById(ResIdWithUnkownType);
 }
like image 541
OneWorld Avatar asked Oct 05 '10 14:10

OneWorld


People also ask

How do I know the type of view?

final View view=FLall. getChildAt(i); if (view. getType()==ImageView) { ... }

What is android view view?

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup.

What is view in xml?

A View occupies a rectangular area on the screen and is responsible for drawing and event handling. Views are used for Drawing Shapes like Circles,Rectangles,Ovals etc . Just Use View with background and apply a Shape using Custom Drawable.

What is view tag in android?

Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure. Reference: http://developer.android.com/reference/android/view/View.html.


1 Answers

The second block would work just fine. The problem is the first one: findViewById returns a View object always, and Bitmap is not a View, so the first if statement will never be executed.

like image 74
Cristian Avatar answered Oct 03 '22 13:10

Cristian