0

I am not getting to how to know to which layout it is point because instead of giving the full name like r.layout.activity_main it has given the id in the form of integer.

How to get the location if the integer id is given how to convert it?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • **"...it has given the id in the form of integer."** : I don't understand what you mean. What *exactly* has given the id as an integer? All resource ids are integers. – Squonk Apr 27 '14 at 08:50
  • i want know the actual path id like r.layout.id instead of resource how to convert it nd where to put the code – user3526871 Apr 27 '14 at 09:15

2 Answers2

0

use

getResources().getResourceName(int resid);

read more in that thread

Community
  • 1
  • 1
infm
  • 52
  • 1
  • 2
  • 10
0

To get the full id like R.id.your_id you have to make two calls:

  • getActivity().getResources().getResourceEntryName(int);
    Which returns the identifier your_id

  • getActivity().getResources().getResourceTypeName(int);
    Which returns the type of the resource like id, string, layout

As a note: Make sure the id with the corresponding value exists! Otherwise you will get a NotFoundException.

Steve Benett
  • 12,843
  • 7
  • 59
  • 79
  • I did this in a Fragment, that's why I use getActivity(). To use it in your Activity get rid of the getActivity() call. If you wanna call it in a custom class pass a valid context and call: context.getResources()... – Steve Benett Apr 27 '14 at 09:15