May 29 | 8:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Vasanthi | has entered the room |
Mark M. |
hello, Vasanthi
|
Mark M. |
how can I help you today?
|
May 29 | 9:00 AM |
Vasanthi |
Hello, Mark. Thank you.
|
Vasanthi |
I have a few questions and would appreciate if you could answer them
|
Mark M. |
I can try
|
Vasanthi |
Thanks.
|
Vasanthi |
1. Simple_list_item_2 – how come that doesn’t have a layout as the root element?
|
Mark M. |
hold on
|
Mark M. |
OK, I am confused
|
Mark M. |
If you are referring to android.R.layout.simple_list_item_two, it uses a TwoLineListItem as the root element, holding a pair of TextView widgets
|
Mark M. |
er, sorry, android.R.layout.simple_list_item_2
|
Vasanthi |
That is the one.
|
Mark M. |
I guess I do not understand your question, then
|
Vasanthi |
I thought if you have more than one widget in a layout, the root has to be a layout
|
Mark M. |
no
|
Vasanthi |
Sorry, my laptop is very slow..
|
Vasanthi |
So, there is no rule that a layout has to be the root element?
|
Mark M. |
or, rather, it depends upon what you mean by "the root has to be a layout"
|
Vasanthi |
Now I am confused
|
Mark M. |
there are many things in Android that use the term "layout"
|
Mark M. |
with respect to TwoLineListItem, it is a (now deprecated) subclass of RelativeLayout
|
May 29 | 9:05 AM |
Vasanthi |
OK, now I understand.
|
Mark M. |
if by "a layout has to be the root element", you mean "a Java class that ends in Layout has to be the root element", that is most certainly not the case
|
Vasanthi |
Yup, now I understand. Thank you.
|
Mark M. |
the root view element of a layout resource file could be a <fragment>, a <ViewPager>, a <TextView>, etc.
|
Vasanthi |
OK. Can it be a class I have extended from one of the Layout classes?
|
Mark M. |
I do not know what "one of the Layout classes" means
|
Vasanthi |
Sorry for my wording. a widget extending one of the Layouts?
|
Mark M. |
I do not know what "one of the Layouts" means
|
Vasanthi |
for e.g.RelativeLayout or LinearLayout
|
Mark M. |
try asking a question that does not involve the word "layout" used on its own, as there are many things in Android that are called "layouts"
|
Mark M. |
those classes are not magic
|
May 29 | 9:10 AM |
Mark M. |
in a layout XML resource file, the parent of view element is going to be a subclass of ViewGroup in most cases
|
Mark M. |
RelativeLayout happens to inherit from ViewGroup
|
Mark M. |
ViewPager happens to inherit from ViewGroup
|
Vasanthi |
Now, I understand.
|
Vasanthi |
That has cleared my doubt.
|
Mark M. |
some subclasses of ViewGroup do not use child elements in layout XML resource files (e.g., ListView)
|
Vasanthi |
2. What will happen if we don’t use Adapters? Say for e.g. can I have a list of items and display them in a ListView? What does the Array Adapter provide us?
|
Vasanthi |
Sorry.
|
Mark M. |
"can I have a list of items and display them in a ListView?" -- if you have an adapter somewhere, yes
|
Refael O. | has entered the room |
Vasanthi |
Hi Rafael
|
Mark M. |
an AdapterView, like ListView, works with Adapter objects to determine its contents
|
Mark M. |
(BTW, hello, Refael -- I will be with you in a moment!)
|
Refael O. |
Hi Vasanthi, Mark :)
|
Vasanthi |
Mark, I am trying to digest what you have written, so will take a few mins.
|
Mark M. |
OK, let me take a question from Refael in the meantime, and I will be back with you shortly
|
Mark M. |
Refael: your turn! do you have a question?
|
Vasanthi |
OK, thank you.
|
Refael O. |
actually mark I have 3 :)
|
Mark M. |
give me the first one for starters
|
May 29 | 9:15 AM |
Refael O. |
sure, ok so first off I would like to ask, I was following your github project, it gave me TONS of help, the one regarding AlarmManager with the OnBoot receiver
|
Refael O. |
I am using that code to start an alarm manager on repeat, that opens a service that runs a few actions for a few seconds and then closes. the alarm repeats every 10 minutes.
|
Refael O. |
problem is, if my app crash, the alarm stops repeating itself
|
Refael O. |
I've been doing some digging and I have no good idea as to how to solve it
|
Mark M. |
what method are you calling on AlarmManager to set up the alarm?
|
Refael O. |
one sec
|
Refael O. |
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10000, TIME, pi);
|
Refael O. |
TIME is 10 minutes
|
Refael O. |
pi is my PendingIntent
|
Mark M. |
I am not aware that an unhandled exception would unschedule an alarm
|
Mark M. |
though you are the second person to mention this behavior in the past week or so
|
May 29 | 9:20 AM |
Mark M. |
I'll need to run some experiments to see if I can reproduce the effect
|
Refael O. |
every 10 minutes my service runs and among other things it writes a log into a .txt file of the exact time it did it's job
|
Refael O. |
for some reason I noticed when i'm crashing
|
Refael O. |
the alarm stops
|
Mark M. |
what version(s) of Android are you seeing this on, and what is your targetSdkVersion?
|
Refael O. |
minSdk 14, targetSdk 21
|
Refael O. |
I am testing it on the latest android version, on Nexus 6
|
Mark M. |
OK, I'll run some tests as part of my overall "OMG M!" battery of work I need to get done
|
Mark M. |
let me take a question from Vasanthi, and I'll be back with you in a bit
|
Mark M. |
Vasanthi: your turn! do you have a question?
|
Refael O. |
sure thing
|
Vasanthi |
Yes, have some more. So, according to your answer about adapters, without an adapter, I can't display a list of items in a view?
|
Mark M. |
to use an AdapterView, you need an Adapter
|
Mark M. |
you can use RecyclerView, but it needs a RecyclerView.Adapter
|
May 29 | 9:25 AM |
Vasanthi |
OK. What does the Array Adapter provide us? Does it provide pagination?
|
Vasanthi |
Or is the pagination provided by the ListView that I am using?
|
Mark M. |
neither; there is no pagination
|
Mark M. |
presumably, you are a subscriber to my book (by virtue of being in this chat)
|
Vasanthi |
YES.
|
Mark M. |
then I suggest that you read "AdapterViews and Adapter"
|
Mark M. |
it starts on page 249 of Version 6.6 of the book
|
Vasanthi |
Yes, I have read that chapter and did the examples as well.
|
Mark M. |
then I don't know what I can tell you
|
Vasanthi |
According to page 233, ListView knows how to scroll. Then why is my ListViewDemo not scrolling?
|
Mark M. |
perhaps you don't have enough data that it needs to scroll
|
Vasanthi |
No, I have more items than what it displays.
|
Mark M. |
then there is a problem with your device/emulator, or something
|
Vasanthi |
I am using the emulator. If I want to debug, can I debug? Where should I place the break point?
|
Mark M. |
I have no idea
|
Vasanthi |
OK. I have few more questions, so if you want to answer Refael's and come back to me?
|
May 29 | 9:30 AM |
Mark M. |
OK
|
Mark M. |
Refael: your turn! do you have another question?
|
Refael O. |
yup
|
Refael O. |
Another problem I've been having this week is with design, I need to create a facebook like card item, but the whole card has to present an imageview, and it needs to have rounded corners, and a shadow
|
Refael O. |
Once again, I never come to you with a problem before I got my hands really dirty first..
|
Mark M. |
sounds like a CardView wrapped around an ImageView
|
Refael O. |
How am I supposed to also get rounded corners and shadow too? I tried several way that I saw on stackoverflow, none of them seemed to work
|
Mark M. |
CardView has rounded corners and a shadow
|
Refael O. |
CardView?
|
Refael O. |
googling
|
Mark M. |
it came out as part of the Android Support package last yaer
|
Mark M. |
er, year
|
Mark M. |
it's a stock implementation of the card-style UI that you describe, as a subclass of FrameLayout (IIRC)
|
May 29 | 9:35 AM |
Mark M. |
on Android 5.0+, it uses the system-supplied elevation-based drop shadow
|
Mark M. |
on older devices, it emulates a drop-shadow using a nine-patch PNG or something
|
Refael O. |
wow, never heard of it before, and didn't found any trace of it in my search..
|
Mark M. |
I have some examples of it in my RecyclerView chapter
|
Mark M. |
it's pretty much just a decorating container class -- wrap it around something else to give it the card-like look
|
Refael O. |
yeah I saw the elevation one, works really well, but I have to support threw to api 14
|
Refael O. |
hmmm so, wait, cardview can be supported to api 14?
|
Mark M. |
it works back to API Level 7
|
Refael O. |
wow amazing
|
Refael O. |
looks neat
|
Mark M. |
anyway, it's worth trying for your use case
|
Refael O. |
ok so thats good for me, ill play around with it, Vasanthi? you're up? or should I fire away my 3rd question?
|
Vasanthi |
Yup.
|
Mark M. |
Vasanthi: your turn! do you have another question?
|
Vasanthi |
the ArrayAdaptor’s getView
|
Vasanthi |
a. What are the parameters int position (I assume that it is the position of chosen item within the list), View convertView and ViewGroup parent ?
|
Mark M. |
again, this is covered in the chapter that you read
|
Mark M. |
position is the index into your collection of model data
|
Vasanthi |
Just wanted to figure out whether this gets called for for each and every item in the list to be displayed?
|
Mark M. |
convertView is either null or a previous View that you returned from an earlier call to getView(), for recycling purposes
|
Mark M. |
parent is the ListView itself
|
Mark M. |
yes, it is called for each item in the list
|
Mark M. |
at least, when those need to be shown, or possibly cached
|
Vasanthi |
Thank you.
|
Vasanthi |
Its Refael's turn
|
Mark M. |
so, in a 25-item ListView, where 8 rows are visible, getView() will be called at the outset 8+ times, but not all 25
|
May 29 | 9:40 AM |
Vasanthi |
OK.
|
Mark M. |
Refael: back to you!
|
Refael O. |
so, my last question.. I have a layout in my main screen, I need to present a list of users inside those card views with just talked about, the list view is vertical, my problem is.. at the top of that screen I need to have another listview, this one is horizontal, and it has only 10 items displaying my top10 users. I'm wrapping all that screen in a scrollview so I can scroll the entire screen down.
|
Refael O. |
but that's creating a problem using the horizontal scrolling
|
Mark M. |
have the horizontal thingy be a row in the ListView
|
Refael O. |
you scroll to the sides and also pull the scrollview down/up on the same time
|
Mark M. |
rather than wrapping the whole structure in a ScrollView
|
Mark M. |
or use addHeaderView() on the ListView to add your horizontal thingy
|
Refael O. |
hmm, interesting approach
|
Refael O. |
you're just brilliant Mark! how come I didn't think of it
|
Mark M. |
I will go to great lengths to avoid trying to do the touch event hacking necessary to have a vertically scrollable thingy in a ScrollView
|
Mark M. |
now, that may not completely solve your problem, but it gets rid of one item (the ScrollView) that's fighting over the touch events
|
Refael O. |
yeah, but i will also be able to scroll down in that list
|
May 29 | 9:45 AM |
Mark M. |
it may clear up your problem entirely, or you may still have issues, because ListView interferes with the horizontal thingy's touch events too
|
Mark M. |
I haven't tried putting horizontally-scrollable content into a ListView, so I don't know how well that works
|
Refael O. |
ok, i'll try that and see for myself =]
|
Refael O. |
as for the first question I had, regarding the alarm manager, is there a way to check if an alarm manager is now active?
|
Mark M. |
adb shell dumpsys alarm
|
Mark M. |
it will show you all scheduled alarms
|
Mark M. |
if yours is scheduled, it will show up in the list
|
Mark M. |
note that in your case, setRepeating() is inexact
|
Refael O. |
would you recommend that as a solution? to check if there's a scheduled alarm, and if not, then to reschedule?
|
Mark M. |
oh, I thought you meant for debugging
|
Mark M. |
I am not aware of a reliable way to determine if your alarm exists at runtime
|
Mark M. |
and, given changes coming in M, frankly, the whole "do stuff periodically in the background" area is a serious mess
|
Refael O. |
hmm, then how would you approach such a problem? I only run this schedule once when user signs up, and then the only time it goes back is after reboot, I restart the alarm OnBoot..
|
May 29 | 9:50 AM |
Refael O. |
and M has a lot of time until it reaches market, I am not worried about this yet ;]
|
Mark M. |
well, my old recommendation would be to not only log your events, but check those logs
|
Mark M. |
if the last time you got control was plausible (e.g., you want every 10 minutes, you last got control 8 minutes ago), you just continue on
|
Mark M. |
if the last time you got control is implausible (e.g., you want every 10 minutes, you last got control two weeks ago), you set up your alarms again
|
Mark M. |
you need this for Force Stop at minimum
|
Mark M. |
and, apparently, in some unhandled exception scenarios
|
Refael O. |
hmmm
|
Refael O. |
that's actually a decent fix
|
Mark M. |
M invalidates this technique, though
|
Mark M. |
let me take a question from Vasanthi, and if there's time, I'll be back with you before the chat ends
|
Mark M. |
Vasanthi: any last questions?
|
Vasanthi |
It is about the min requirement for the system to run Android Studio. My laptop is extremely slow once I start Android Studio
|
Vasanthi |
My laptop has Intel core i3-3217U CPU at 1.80GHz smart cache 3MB with installed memory 4.0GB (3.89GB usable) 64bit op sys windows 8.1. Disk space available 340 GB.
|
Mark M. |
that's pretty light
|
Vasanthi |
View paste
|
Mark M. |
I have a high-end Core i7, 8GB of RAM, and Linux, and it runs fairly well
|
May 29 | 9:55 AM |
Vasanthi |
I have looked at what your book say
|
Vasanthi |
Is yours a laptop?
|
Mark M. |
yes
|
Vasanthi |
I was not sure about buying an i7 laptop as I read that it gets heated up due to turbo boost
|
Mark M. |
that probably depends on the notebook model
|
Mark M. |
I rarely have mine actually in my lap, but from what I can tell, it doesn't get ridiculously hot
|
Vasanthi |
Which model would you recommend?
|
Mark M. |
I have not really looked at current models
|
Mark M. |
mine is a few-years-old Dell
|
Vasanthi |
OK. The Linux, do I need to install that?
|
Mark M. |
because CPUs just haven't gotten any better, and I can put in my own SSD, so until 8GB becomes a limiting factor, this will suffice
|
Mark M. |
you don't need to
|
Mark M. |
plenty of people develop on Windows
|
Mark M. |
I think it runs a bit leaner in terms of RAM usage than do modern versions of Windows
|
Vasanthi |
Yes, I thought so.
|
Mark M. |
Refael: any last questions?
|
Vasanthi |
Thank you very much, Mark.
|
Mark M. |
you're welcome!
|
Refael O. |
Mark, you were incredibly helpful as always, your tips are gold!
|
Refael O. |
thanks a lot !
|
Mark M. |
you too are welcome!
|
May 29 | 10:00 AM |
Refael O. |
btw , are you in Google I/O ?
|
Mark M. |
no, I am not at I|O
|
Mark M. |
here in my office
|
Refael O. |
nothing like home then =)
|
Mark M. |
watched some of the I|O live streams yesterday, and will do so again today
|
Mark M. |
it's a lot less crowded here :-)
|
Refael O. |
yeah me too, been pretty nice to watch
|
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Vasanthi |
Mark, the answers to my first few questions aren't visible now. Is there a way, I could get them?
|
Refael O. |
okie, i'll be leaving. thanks a lot again Mark
|
Mark M. |
the next chat is Tuesday, also at 9am US Eastern
|
Mark M. |
Vasanthi: visit https://commonsware.com/office-hours/ in a few minutes, and you can get access to the whole chat transcript
|
Mark M. |
have a pleasant day, all!
|
Vasanthi |
Thank you, Mark. Bye to Refael and you.
|
Vasanthi | has left the room |
Refael O. | has left the room |
Mark M. | turned off guest access |