0

Is there a way to list all the display fields (view names?) with their ids? This

int id = getResources().getIdentifier(name, "id", context.getPackageName());
View view = findViewById(id);

is fine to return a single id from a name, but what I'd like is an array or map with ids and names. My reasoning is that getIdentifier is discouraged (inefficient), and if there is a quicker way I'd prefer to use it. I have to match a longish list of variable name/value pairs (20-30) from a csv with the matching field name (if it exists) to display the value.

  • You can recursively loop through all the children of your root layout . [Here is an Example](https://stackoverflow.com/questions/2597230/loop-through-all-subviews-of-an-android-view) . And i don't understand why you need such thing .. – ADM Mar 29 '22 at 04:46
  • You can use data binding or view binding. – Karan Mehta Mar 29 '22 at 06:11
  • Thanks. If I use getChildAt(index) (as shown in the example), then it returns the names, but 'index' is not the id of the resource, is it? I'd explore view binding further, except that it looks too complicated for a beginner. – user3825344 Mar 29 '22 at 06:54
  • No. `index` is not the ID of the `View`. If you want the ID, you can call `getId()` on the `View` that is returned from `getChildAt()`. However, this ID is a number, it isn't a name. – David Wasser Mar 29 '22 at 17:32

0 Answers0