3

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?

BlackCat
  • 1,932
  • 3
  • 19
  • 47

1 Answers1

1

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)
david
  • 407
  • 3
  • 11