BlackCat
BlackCat

Reputation: 2044

How to identify which layout xml is running currently?

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

Answers (1)

david
david

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

Related Questions