AndExplore: LayouInflater-access, Recyclerview-Reference

from the CommonsWare Community archives

At October 8, 2019, 1:14pm, Hadysalhab asked:

I would appreciate some clarifications regarding some confusion i experienced when following the AndExplore Book:

Thanks for help Hadi

At October 8, 2019, 11:13pm, mmurphy replied:

I do not like using LayoutInflater.from(). I recommend using getLayoutInflater(). That way, if a class overrides getLayoutInflater(), you get the proper inflater.

Ummm… yes. I am not quite certain why I did it that way. :slightly_frowning_face:

Android Studio did not give us a Toolbar. We added one ourselves, to the activity, in “Setting Up the App Bar”. We then switched to using that layout in a fragment, but the Toolbar needs to be in the activity (for use by the Navigation component). That is why we wind up moving the Toolbar from the original activity layout to the new activity layout. So, I am not quite certain what “default one” you are referring to.

At October 9, 2019, 12:19am, Hadysalhab replied:

First of All, thanks for the clarifications and fast reply.
Regarding the last point , sorry for confusion but i think i got the answer from the official documentation:
this is the link

" This class describes how to use the v7 appcompat support library’s Toolbar widget as an app bar. There are other ways to implement an app bar—for example, some themes set up an ActionBar as an app bar by default—but using the appcompat Toolbar makes it easy to set up an app bar that works on the widest range of devices, and also gives you room to customize your app bar later on as your app develops."

At October 9, 2019, 12:25am, Hadysalhab replied:

I think my confusion was
Toolbar vs Action Bar!?

At October 9, 2019, 11:52am, mmurphy replied:

As I think I mentioned in the book, Google made a mess of all these “bars”. IMHO, “action bar” has two meanings.

One meaning is “the toolbar-like thing that we get from a theme if we do not opt out”. This works, and it is usually my default choice, personally. However, Google promotes developers using Toolbar explicitly, partly with an eye towards more complex scenarios (e.g., collapsing app bar). So, I elected to use a Toolbar in this book.

The other meaning is “a shared spot for menus and toolbar-style buttons that activities and fragments can both contribute towards”. If you are going to use a Toolbar, IMHO it is simpler to make it have the action bar role than it is to create your own API for fragments to control the contents of the Toolbar when the fragment is visible. So, the app is going this route, calling setSupportActionBar() to say “use this Toolbar as the action bar, since our theme did not request an action bar”.