2

Now I am working on a project in which I have to use multiple layouts in single activity. Let me describe with example

For example there is an activity called "DashboardActivity" and I have to create 4 layout for this activity.

If there is flowId=1 from the server I have to apply activity_dashboard_layout_flow_one. Same as like for flowId=2/3/4. I have different layout for all flows like activity_dashboard_layout_flow_two , activity_dashboard_layout_flow_three , activity_dashboard_layout_flow_four etc

Now I am using databinding in my project so simple all layout files generate Binding files. So there is different binding objects in my activity. But I want to use and manage only one binding object to access views from XML files.

So please suggest me how to handle Databinding in this situation. And what is the efficient way to do this in kotlin with databinding

Thank you

sohel.eco
  • 337
  • 2
  • 12
  • I would recommend moving them into fragments and push the desired fragment onto the activity once you have the request response. This way you can handle each layout / binding individually on each fragment and there won't be any mixup. – Brandon Aug 12 '21 at 07:28
  • @Brandon If I do this I have to do same functionality in all these fragments. Here Functionality is same in my case in single activity.. Functionality means api calling, views click and all. – sohel.eco Aug 12 '21 at 08:05

1 Answers1

0

After done some r&d I do the one solution that set binding object as Any type. Theme wise condition to set root layout and make extension functions of all views that return particular view from available 4 binding.

And today I found similar question with similar solution to my solution but this given solution is in better manner than my solution. check out following link

View Binding with 2 possible layouts, assign binding variable to 2 generated binding classes

sohel.eco
  • 337
  • 2
  • 12