ShwetaK
ShwetaK

Reputation: 180

How to get the layout ID of an activity programmatically at runtime

I have a reference to an activity, but I don't know the ID of content view for the activity. I need to find all the views in the layout. Can I get the ID of the layout of an activity programmatically at runtime.

Upvotes: 0

Views: 1318

Answers (2)

SVS
SVS

Reputation: 200

Probably, I don't understand your question, but I think you may get views by there ID using:

View v = activity.findViewByID(required ID)

Upvotes: 0

Buda Gavril
Buda Gavril

Reputation: 21637

I'm not sure if you can get layout id but you ca try with

activity.getWindow().getDecorView().getRootView()

and from here you can get any child view you want

Upvotes: 3

Related Questions