Office Hours — Today, August 18

Thursday, August 13

Aug 18
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Kait
has entered the room
Mark M.
hello, Kait!
how can I help you today?
Kait
Hello mark!
Jeffrey
has entered the room
Kait
I'm trying to make a UI like the event detail in Google Calendar
Mark M.
(BTW, hello, Jeffrey -- I will be with you shortly!)
Jeffrey
Hi Mark, Kait
Kait
Is it possible to have a fragment (like the DetailFragment in List/Detail) put it's content in a layout underneath a CoordinatorLayout?
Mark M.
what do you mean by "underneath"?
Kait
a child view
Mark M.
off the cuff, I don't see why not
4:00 PM
Mark M.
use a FrameLayout as the container for the fragment, if it's a dynamic fragment
Kait
I want a CoordinatorLayout to make the FAB half way between the Toolbar and Fragment content
It doesn't populate the content
just blank
Mark M.
what is "it" in "It doesn't populate the content"?
Kait
It will populate the root/CoordinatorLayout, but on-top-of/overlapping the toolbar then :(
Mark M.
again, I do not know what "it" is
Kait
the content from the Fragment does not show up
it = the app
no error, but no content either
just the Toolbar and FAB and nothing below
Mark M.
is onCreateView() being called on the fragment? if yes, what is the ViewGroup you are being passed as the container? is it what you expect?
have you used Hierarchy View or uiautomatorviewer to see if your content wound up there but in an odd state (e.g., visibility set to GONE)?
Kait
I call inCreateView *in* the fragment
Mark M.
you never call onCreateView()
Kait
I don't know how to do that
"you never call onCreateView()" hmm?
Mark M.
the framework calls onCreateView()
you never call onCreateView() yourself
Kait
on no
I have an onCreateView in the Fragment. I never explicitly call it
Mark M.
OK, is it being called? if yes, what is the ViewGroup that you are being passed in as the container? is it what you expect?
Kait
View paste
this?  View rootView = inflater.inflate(R.layout.fragment_task_detail,
				container, false);
Hoornet
has entered the room
4:05 PM
Mark M.
yes, that container -- put a breakpoint there and confirm that you are being called and that the container is the container that you are expecting
(BTW, hello, Hoornet -- I will be you in a bit, after Jeffrey!)
with regards to Hierarchy View and uiautomatorviewer, these are tools for inspecting a running UI
Hierarchy View gives you more detail but typically requires an emulator
uiautomatorviewer works on production hardware
I cover Hierarchy View in the book (though it may need some updating), and I really need to add uiautomatorviewer
let me take questions from the others, and I will swing back to you in a bit
Jeffrey: your turn! do you have a question?
Kait
OK, thanks
Jeffrey
thanks
View paste (1 more line)
Hi Mark, 

My question is about recyclerview saving state. My app architecture is an Activity which holds a fragment and the fragment holds a recyclerview. I use api to fetch data (page 1,2,3...) and to populate photo in my endless recyclerview.   

when I make a rotation from portrait to landscape, I CANNOT keep the previous view state(scroll position ). That is, my fragment fetches data at the beginning (Page 1). So, I try several ways: 
use setRetainIstance(ture) in onCreate() of my fragment to pass the activity recreate   --- did not work

put LinearLayoutManager.onSaveInstanceState() in the Bundle in onSaveInstaceState
	and get the state in onViewStateRestore    --- did not work

      3. Even I use android:Configuration: orientation in AndroidManifest.xml 
 --- did not work (I   know it not a good way) 

I guess I  am on the wrong track to solve the problem using Bundle or my coding logic is wrong in the fragment. 

...
Mark M.
um, at least for ListView, I think the standard recipe is to get the scroll position, store it yourself in the saved instance state Bundle, and restore it yourself
Jeffrey
if I store the scroll position, how to use it?
Mark M.
well, I'm poking at the RecyclerView docs now
and I'm not really sure what the equivalent recipe would be for it
4:10 PM
Mark M.
I'll have to do some research on this point and add it to some future edition of the book
(not v6.8, which will be out next week, most likely)
Jeffrey
sounds great!
Mark M.
sorry I could not be of greater assistance on that one
let me take questions from the others, and I'll be back with you in a bit
Hoornet: your turn! do you have a question?
Jeffrey
Thanks
Mark M.
Hoornet: your turn! do you have a question?
Hoornet: if you return and have a question, let me know
Kait: your turn! do you have another question?
4:15 PM
Kait
No, it's just this :(
Mark M.
there's not much more I can really tell you
I am not aware that a CoordinatorLayout eats fragments for lunch
so, either the fragment is not being created, or its views are not going where you think they are, or those views are in some state (e.g., visibility GONE) that you are not expecting
breakpoints or logging should tell you the first one
Hierarchy View and/or uiautomatorviewer can help with the latter two
Kait
well, in a detail activity layout (in list/detail) that has a Toolbar, FAB, and container for the coresponding fragment -- how would you set up that layout file? It should be a pretty simple file
Mark M.
off the top of my head, I have no idea
while I cover some of the mechanics of using those widgets in my book, I don't deal with them much otherwise
Kait
ok. thanks for trying. I'll try your suggestions and SO
Mark M.
sorry I could not be of more help
Jeffrey: your turn! do you have another question?
Jeffrey
Thanks, According to my previous question, do you know any examples in your book that I can refer ? or do you know any other key words related my problem so that I can search my problem on the web site precisely?
4:20 PM
Mark M.
well, I just ran a Google search on: recyclerview scroll position configuration change
4:20 PM
Hoornet
has left the room
Mark M.
looks like it's the job of the LayoutManager, which is why I wasn't seeing the details on RecyclerView itself
Jeffrey
ok got it. I use it
Mark M.
if that is not working, that suggests perhaps a timing issue
if you replace your adapter after updating the scroll position, the scroll position is probably lost
Jeffrey
oh!! probably!!
so that is why I am talking about my coding logic
if I use the linearManager to save my recyclerview state
how do I know it is a correct state?
Mark M.
I am not sure what "a correct state" means here
Jeffrey
previous state before I rotate handset
4:25 PM
Jeffrey
I can save previous recyclerview state and rotate my handset and get the previous state out
Mark M.
well, going by the blog post that I linked to, rather than immediately applying the LayoutManager state in onRestoreInstanceState(), you cache it, set up your adapter, then apply the state
Jeffrey
thanks I will try it
may I ask another question? if there is no one have question
Mark M.
basically, calling setAdapter() on a RecyclerView is a full reset, more or less, and it should dump all prior state, because as far as RecyclerView knows, that state is obsolete
Kait: if you have another question, chime in
Jeffrey: pending another question from Kait, go right ahead
Jeffrey
thanks
When I use third-party Library for example ActionBarPullToRefreah, I import the project from gradle(app). Then, I want to add some methods in the the project. Can I do it? How? Does you book provide the similar materials?
Mark M.
do you mean that you want to add some methods to ActionBarPullToRefresh?
Jeffrey
yes
Mark M.
you need to download the source code and import it as a library module to your Android Studio project
Jeffrey
I did.
Mark M.
you would replace the previous Maven-based dependency (e.g., compile 'group:artifact:version') with a reference to the library module (e.g., compile project(':whateverYouCalledIt'))
4:30 PM
Mark M.
then, edit the code in the module to suit your needs
if you want to be contributing your changes back to the project, fork the repo, issue pull requests, and so on
while I talk about library modules, I do not cover this specific scenario
Jeffrey
got it, thanks. try it later
may I ask another question?
Kait
Oh, I do have another question. Do you recommend any particular library for adding charts?
Mark M.
Kait: I have not had a chance to use any, so I am afraid I don't
Kait
Thanks, just wanted to ask
take it away Jeffery!
Mark M.
Jeffrey: go ahead
4:35 PM
Jeffrey
if I found some open source project on Github, I would like to clone it as my local project. Usually, I cannot because of Grading setting. Do you have any tutorial materials?
Mark M.
sorry, but I do not understand your problem
what is "Grading setting"?
Jeffrey
gradle setting
Mark M.
what is the problem with the gradle setting
?
Jeffrey
yes, I can get all project java files in my IDE. but I cannot run it
Mark M.
what happens when you try to run it?
Jeffrey
let me show you a message. wait a second
4:40 PM
Jeffrey
The project XXX may be using a version of Gradle that does not contain in the method
Gradle setting
Mark M.
could you take a screenshot, then use the "Upload a file" link on the right to upload it into the chat room?
Jeffrey
The build file may be missing a Gradle plugin
ok, thnaks
Mark M.
it may be easier for me to understand what you are seeing if I can see it :-)
Jeffrey
Mark M.
your problem is that the project in question has not been updated in ~1 year
and it is still using an old version of the Gradle for Android plugin, where we had a runProguard() method
Jeffrey
I do know, sorry
do not
Mark M.
I recommend that you upgrade the project's Gradle (gradle/wrapper/gradle-wrapper.properties file, distributionUrl value) to something current, like 2.4
then upgrade the Gradle for Android plugin (typically the top-level build.gradle file, classpath statement) to something comparable, like 1.3.0
then, you will need to fix up the old build.gradle file for anything that has changed, like replacing runProguard() with minifyEnabled()
another option would be to create a new project (so you get new Gradle/Gradle for Android settings), copy over all the source into that new project, and try that
basically, leaving the old Gradle stuff behind
4:45 PM
Jeffrey
How to do it in detail? do you have any educational materials in your book? I am not good at using gradle
Mark M.
"How to do it in detail?" -- beyond what I already have here in the chat, that is beyond the scope of these chats
"do you have any educational materials in your book?" -- I have ~80 pages on Gradle and Gradle for Android, but I do not have a specific recipe for how to upgrade somebody else's out-of-date project
Jeffrey
ok, I will try it later. Thanks a lot
Mark M.
Jeffrey
yes
Mark M.
step #1: change distributionUrl in https://github.com/Aesthetikx/hubski-android/bl... to http\://services.gradle.org/distributions/gradle-2.4-all.zip
4:50 PM
Mark M.
step #2: change classpath 'com.android.tools.build:gradle:0.7.+' to classpath 'com.android.tools.build:gradle:1.3.0'
step #2a: consider changing both mavenCentral() occurrences to jcenter(), particularly if later on Gradle complains that it cannot find that artifact listed in the classpath value
step #3: replace apply plugin: 'android' with apply plugin: 'com.android.application'
step #4: unless you are planning on shipping this as a production app, just get rid of the whole buildTypes {} closure for now
that should clear up the problem from the screenshot
Jeffrey
Cool ! I will try it later. Thanks for your time to answer my questions.
4:55 PM
Mark M.
if anyone has any questions, go right ahead -- we're running out of chat time!
Kait
I'm heading off. Thanks again for your time and expertise!
Kait
has left the room
5:00 PM
Mark M.
and that's a wrap for today's chat
the transcript will be posted shortly to https://commonsware.com/office-hours/
the next chat is Thursday at 7:30pm US Eastern
have a pleasant day!
Jeffrey
has left the room
Mark M.
turned off guest access

Thursday, August 13

 

Office Hours

People in this transcript

  • Hoornet
  • Jeffrey
  • Kait
  • Mark Murphy

Files in this transcript