Office Hours — Today, October 6

Yesterday, October 5

Oct 6
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:15 PM
MyWay
has entered the room
Mark M.
hello, MyWay!
how can I help you today?
MyWay
hello again Mark :)
I was switching my fragments, but... doesn't ArrayAdapter support Compat? :(
Mark M.
ArrayAdapter has nothing to do with fragments or ...Compat
what exactly is your problem?
MyWay
so I can change the call to the constructor public MyPagerAdapter(FragmentManager...)?
Mark M.
there are four implementations of PagerAdapter supplied by the Android Support libraries
4:20 PM
Mark M.
one axis is whether they work with native fragments or the fragments backport
the android.support.v4 edition of FragmentPagerAdapter and FragmentStatePagerAdapter use the backport
the android.support.v13 edition use native fragments
they take the corresponding v4 or v13 FragmentManager in their constructor
you need to synchronize which PagerAdapter classes you are using with your fragment implementation
MyWay
so I can switch to the support.v13 and chain the fragmentmanager of v13
Mark M.
presumably, yes
MyWay
I thought I needed your arrayadapter to support it
Mark M.
do you mean ArrayPagerAdapter?
MyWay
yes
sorry
Mark M.
the main ArrayPagerAdapter works with native fragments
there's a sub-package that has an ArrayPagerAdapter clone that works with the backport
"There are two implementations of ArrayPagerAdapter. One, in the com.commonsware.cwac.pager package, is designed for use with native API Level 11 fragments. The other, in the com.commonsware.cwac.pager.v4 package, is designed for use with the Android Support package's backport of fragments. You will need to choose the right ArrayPagerAdapter for the type of fragments that you are using."
MyWay
ah, so I need v4 of everything
Mark M.
consistency is key
MyWay
^^
thank you
4:25 PM
MyWay
does google said something about one has to prefer v4 or v13?
in my case I need v4 to use your library, but in general?
Mark M.
you don't need to use v4 to use my library
again, there are *two* ArrayPagerAdapter implementations
one for the v4 fragments backport
and one for native fragments
that being said, there are pros and cons with using the backport
clearly, if you want fragments *and* want to support pre-API Level 11 devices, you need the backport
MyWay
but I can't use v13 with your library, right?
yes
Mark M.
ArrayPagerAdapter is a *replacement* for FragmentPagerAdapter and FragmentStatePagerAdapter
just as FragmentPagerAdapter and FragmentStatePagerAdapter have two implementations (backport and native), ArrayPagerAdapter has two implementations (backport and native)
"v13", in the context if this chat, refers to FragmentPagerAdapter and FragmentStatePagerAdapter, which you probably are not using, if you are using ArrayPagerAdapter
MyWay
yes
4:30 PM
MyWay
ok, probably I'm doing confusion between the "version" of the Fragments and the Adapter
Mark M.
fragments come in two flavors: the backport (from support-v4) and native (added in API Level 11)
MyWay
so "all" the adapters (native and your) support all those versions
Mark M.
yes
the slight exception is that for the zero devices running Android 3.0 and 3.1, you can't use the v13 editions of FragmentPagerAdapter/FragmentStatePagerAdapter, for some reason
MyWay
I think it's clear now, thank you, I thought I had to use one specific version of the adapter, but as you said, there are two implementations
Mark M.
right
nothing with respect to ViewPager constrains you in terms of whether you use native fragments or the backport
whether you use Google's supplied PagerAdapter implementations, mine, or somebody else's, or your own
MyWay
oh, what about ViewPager?
Mark M.
ViewPager works back to API Level 4, and ViewPager itself has nothing to do with fragments
PagerAdapter implementations may or may not work with fragments
ViewPager just works with a PagerAdapter
MyWay
yes, this seems reasonable
4:35 PM
MyWay
so, I switch my fragments to FragmentCompat
FragmentCompat is like Fragment v11?
Mark M.
no
FragmentCompat is a collection of four static helper methods
for some things added to native fragments after API Level 11, these methods allow you to ask for some capability (e.g., request runtime permissions), without having to do version checks yourself
the static methods check the version for you, doing the "real thing" on newer devices, and doing nothing (or something benign, or a work-alike) on older devices
MyWay
simply switching to it, I'm getting some method not found, like getFragmentManager(), getArguments()
so something else changed?
Mark M.
"switching to it" -- I do not know what "it" is
MyWay
switching to FragmentCompat, from native Fragment
4:40 PM
Mark M.
again, FragmentCompat is not something you "switch" to
do you mean that you switched to android.support.v4.app.Fragment?
MyWay
I replaced import android.app.Fragment; with the FragmentCompat, so this is wrong
because it's not a replace of it
Mark M.
yes, FragmentCompat is not an implementation of fragments, but just a helper class
MyWay
so I just use FragmentCompat statically, when I need, but I still import the "old" native fragment
Mark M.
yes
MyWay
like if I know I need something, if I'm on Android 6 it is going to ask the permission, else not
ok, I think now this is clear too, thank you
Mark M.
right
MyWay
so basically I don't even need to change anything, because I'm using the "right" Fragment and the Adapter
I mean, I'm already material-ready
Mark M.
I can't really answer that, as I can't see your code from here :-)
MyWay
eheh
4:45 PM
MyWay
the same applies to preferences, right? e.g. I'm extending the native EditTextPreference, this is ok, I don't need the support version
Mark M.
definitely if you are using the native PreferenceFragment
if you are trying to use the backported PreferenceFragment we discussed yesterday, then I don't quite know the rules, as I have not played with thatyet
er, with that yet
MyWay
I've tried playing with it, but it seems a bit harder to manage headers, there are two calls
and you have to invent something to "put" and then "select" the right key
to choose which category to open
Mark M.
yes, they seem to have backed away from preference headers, for some reason
MyWay
I've also tried the thing you told me about the icon, I've restored it and... its size are wrong
lol
Mark M.
there's probably a way to force it to work better, but I never spent the time to try to figure it out
as it'd be a nasty, assume-the-internal-workings sort of hack
MyWay
yes
It's like they don't want to, so...
I like the idea of a standard, even if I don't like this thing specifically
4:50 PM
MyWay
ah yes, the "problem" was I'm extending PreferenceActivity
I could add a toolbar, but probably I will wait
I see somebody on stackoverflow is copying AppCompatPreferenceActivity.java
4:55 PM
Mark M.
yeah, creating one should not be too hard
that's what's handy about Android being largely open source
MyWay
thank you very much Mark
Mark M.
you're welcome!
5:00 PM
Mark M.
and that's a wrap for today's chat
MyWay
:)
Mark M.
the transcript will be posted to https://commonsware.com/office-hours/ shortly
MyWay
Bye, have a nice day
thank you
Mark M.
the next chat is tomorrow at 9am US Eastern
have a pleasant day!
MyWay
has left the room
Mark M.
turned off guest access

Yesterday, October 5

 

Office Hours

People in this transcript

  • Mark Murphy
  • MyWay