Quick Links

how to navigate through multiple layouts, from one axml layout to another by the click of a button

I am working on a project with multiple axml layouts, I want to move from one layout to the other by the click of a button. When I move from my main page to login page by using the setcontentview function, it works but when I use similar codes to move to other layouts it doesn't work.

Answers

After using SetContentView to navigate to a new layout, you have to register the new layout's control event on the activity. Otherwise, you can't access the button's click event on the new layout.
Usually, when we want to display a new page we use Intent to show a new activity. In that new activity, we could set the content view, register the button's event on the OnCreate lifecycle event: