[Android] How to get XML file behind the corresponding resource ID?

How would you get the XML resource file linked to something like R.layout.activity_main in your kotlin/java code? I believe I can search for "activity_main" using the FilenameIndex.getFilesByName but isn't the PsiElement of R.layout.activity_main already linked to a physical file? If so, then I'd rather get the reference directly, avoiding the unnecessary global search by file name.

Thanks.

P.S. People post a lot of code snippets on this forum, would be nice to see some code formatting support in the future.

0
1 comment

I'd recommend to stay with FilenameIndex, it's very fast. Resolving PsiReference would do the same thing internaly, but you'll have to find the reference first.

0

Please sign in to leave a comment.