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 :)
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.
Comments