Is it possible to find a view by its name rather than its id.
findViewById(R.id.someView);
but I would like to do something like this:
findViewByName("someView");
you have to find views by identifier when dealing with xml, but you can look up the identifier by using getIdentifier(String name, ...) which is useful if you have your layouts numbered for example. Just be aware that such a lookup is relatively expensive.
to complete the answer
int id = getResources().getIdentifier(name, "id", context.getPackageName()); View view = findViewById(id);
2.1m questions
2.1m answers
60 comments
57.0k users