Reputation: 2044
I have to layout xml named activity_layout_1 and activity_layout_2 and one common Activity. Based on different conditions, I set contentview of the two xml In a case, I need to check which layout is currently set.
I can get the id as below:
View currentView = this.getWindow().getDecorView().findViewById(android.R.id.content);
int id = currentView.getId();
Is there a better way to get/identify current layout running?
Upvotes: 1
Views: 71
Reputation: 441
That id is the id of android.R.id.content no the id of the current layout.
A better way of doing is with tags setTag()
and getTag()
Like:
View view = inflater.inflate(R.layout.fragment, container, false);
view.setTag(R.layout.fragment)
Upvotes: 1