From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add an Up button to a secondary fragment

Add an Up button to a secondary fragment

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Add an Up button to a secondary fragment

- In my application's current state, I can select a data item from the RecyclerView and that takes me to the detail fragment. Now I want to add a navigation user interface element, an up button that the user can press to return back to the main fragment. I'll start in the detail fragment class. And first I want to do a little code reorganization. When I first created my application, all the files relating to my main fragment were placed in a single package. I want to continue to follow that pattern. So I'll go to my base package and I'll create a new package under that, and I'll call it ui.detail. Then, I'll drag my detail fragment class into the new detail package. So everything having to do with the detail fragment is here and everything having to do with the main fragment is here. Next, I'm ready to display an up button. I'll do that work here in the detail fragment class in the onCreateView function. I'm going to call function called setDisplayHomeAsUpEnabled and pass in a value…

Contents