How can I get android View kind programmatically?

이영우

I want to get View object programmatically. But, not fixed View kind, like.. RadioButton..Button.. I only want to know View kind for View's properties. Is it possible?

Please see this :

String idString = "view_from_xml_id";
int id = getResources().getIdentifier(idString, "id", getPackageName());
View iDontKnowWhat = findViewById(id);

The [iDontKnowWhat] view object is Just View. But, I want to cast this [iDontKnowWhat] view object to RadioButton, Button, EditText...Case by Case.

I want like this :

String idString = "view_from_xml_id";
int id = getResources().getIdentifier(idString, "id", getPackageName());
View iDontKnowWhat = findViewById(id);

if(iDontKnowWhat == RadioButton)
  // @Do something..
else if(iDontKnowWhat == EditText)
  // @Do Something..

Can I implement it? Please help me sir :)

noman404

Do not use == (equals), that actually compares the values, not the objects. Use instanceof and check the view like this


if(view instanceof TextView){ //TODO your logic }elseif(....

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I add focus programmatically in Android?

How can i get csrftoken in view?

How can I programmatically get the JNA version being used at runtime?

where can I get these kind of exercises to solve?

How can I assign an ID to a view programmatically?

Get view name programmatically in Android

How can I get context from a view?

How can I get the connected Facebook page id of an Instagram business account programmatically in Android?

How can I get the Terraform module name programmatically?

How can I lock an icon in Android (programmatically)?

How can I scroll my entire view, including images programmatically

How can I make this kind of list view within layout?

How can I programmatically include layout in Android?

How can I programmatically pin a textfield to the top of a view?

Android: what kind of UI component is it and how can I create it?

How Can I Get The Value Of The Components That I Created Programmatically?

How can I set View (editor) options programmatically?

How can I programmatically cause a delay in Android?

Android how can I assign custom parameters programmatically to my inflated view?

How can i get current playing song in Android programmatically

How Can I Do Android Numpad Programmatically

How can I programmatically get this layout in tmux?

How can I programmatically get beans from an OSGI blueprint?

How can i programmatically add a view from XML to a Layout?

How to programmatically get the XML code of a view in Android?

How can I convert an XML to make a programmatically view in Android Java

How can I get this kind of Color Picker View in my iOS app?

how can I get this kind of box shadow or outline?

How can I get this kind of data in JS?