Office Hours — Today, July 31

Tuesday, July 29

Jul 31
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
ming
has entered the room
Mark M.
hello, ming!
how can I help you today?
ming
Hi Mark!
First question is about notification
Is there a way to change the height my notification snippet takes in notification center?
Mark M.
not exactly
there are the big notification styles
but you don't control when those are shown
it's based on where you are in the notification drawer and user preference
otherwise, AFAIK, the height is controlled by Android, not developers
7:30 PM
ming
oh
i see an app called
watchon
it shows a remote on notification center, and it takes unusually large height
Mark M.
if you mean Samsung's app, I don't see their notification drawer entry in the Play Store screenshots, so I haven't seen this
ming
i saw it on my friend's samsung s4, is it because samsung made modification to the OS?
Mark M.
it's possible that WatchON has different capabilities on a Samsung device than on others
in fact, looking at the available installation targets, it looks like it might *only* be available for Samsung devices
ming
oh yes that makes sense
Mark M.
hence, they may be doing some sneaky stuff that only works on their devices
7:35 PM
ming
I really wish we can customize the notification center, just like in iOS8
ok, lets talk about listviews. I still don't fully understand how it reuses the view
so in getview() method, one of the argument is convertview, that is the view populated already and will be reused right?
Mark M.
if there is a view to reuse, yes
ming
so let's say i have 10 items in my list, my screen can display 5 of them and it is displaying the first 5 items
Mark M.
OK
ming
I am scrolling so that my 6th item is about to appear
so for this 6th item, which view is it going to reuse?
Mark M.
none of them
convertView will be null, in all likelihood
as the original five views are still visible
ming
wait, so when is a view being reused?
Mark M.
it won't be reused until it is no longer visible
in a ListView, it will have scrolled off the screen
we can't reuse it while it is still visible
7:40 PM
ming
oh i see, so lets say my 1st item is off the screen, 2 to 6 are being displayed
at this time, is the 1st item's view being reused?
Mark M.
probably not
the 1st item was probably visible while the 6th was coming onto the screen
if you scroll up one more, so that 3 to 7 are being displayed, the 1st might be reused at that point
ming
but who's going to reuse 1st view?
7?
Mark M.
yes
when getView() is called for the 7th row, it might be handed the now off-screen 1st row for reuse
ming
oh i see
lets say all items contains a textView, and the text displayed is their corresponding number, 1st item is 1, 2nd item is 2 etc..
when 7th item is using 1st view
if i dont set the text to be 7, is it going to display 1?
7:45 PM
Mark M.
if getView() was passed the 1st row for reuse, then yes
bearing in mind that populating this TextView might be handled by something you are inheriting in your adapter
and therefore it might be updating that TextView, not you
ming
the only place to update textview is in the getview(), i find the reference to the textview, and call getItem(position) to find the string and set the text
Mark M.
that depends a bit on what adapter class you are extending and whether you are chaining to the superclass in getView()
ming
i dont understand by how it being handled by something else
Mark M.
this is covered in the book
take a look at the activity
and show me where I am setting the TextView myself in a getView() method
as you'll see, I don't have my own adapter class
I am using ArrayAdapter
and ArrayAdapter is populating my TextView
ming
yes
Mark M.
here, I am updating one TextView and one ImageView, but I am inheriting from ArrayAdapter, and it is handling the other TextView
7:50 PM
Mark M.
the same thing holds true with most concrete adapter implementations in Android
ming
oh yes
cos getview() in super class may update the view
Mark M.
right
ming
lets talk more about listview
there is a method called getViewCount() and getViewType()
wait
Mark M.
that's getViewTypeCount() and getItemViewType()
ming
i may got it wrong, let me googleit
oh i see. what are the purposes of those two methods
Mark M.
that's covered in the Advanced ListViews chapter
the chapter begins on page 823 of Version 5.9 of the book
you use those if you will have different sorts of rows, with different layouts
such as header rows and regular rows
getViewTypeCount() says how many different types of rows you have
getItemViewType() returns a value, from 0 to getViewTypeCount()-1, indicating which type of row is used for a particular position
AdapterView maintains separate object pools for view recycling
one pool per row type
7:55 PM
Mark M.
so if you implement getViewTypeCount() and getItemViewType(), you are assured that the row handed to you for recycling in getView() will be of the appropriate layout
so you do not get handed a header row to reuse when you need a regular row, or vice versa
ming
oh i see, (getItem(position) instanceof Integer) this is a really smart check
let's talk about multi threading
To me it seems that asynctask and handler they are two best options
I read the book the big nerd ranch guide, the book says use handler for long running tasks
so how do I decide which on to use
Mark M.
that is impossible to answer in the abstract
you choose your approach based on a specific circumstance
ming
I am sorry :( i know that is toooo abstract
8:00 PM
ming
is there a way I can get access to apps produced by google?
Mark M.
what do you mean?
specifically, what does "access" mean?
ming
for example
email
source code
Mark M.
the Email app is part of the Android Open Source Project
the Gmail app is not
ming
source code for gmail app
Mark M.
to get the source code for Gmail, get a job at Google
ming
oh im not good enough :(
Mark M.
the Email app's source code is at https://android.googlesource.com/platform/packa...
8:05 PM
ming
I think I asked all questions I have for now
Mark M.
OK
note that the transcript for the chat will show up at http://commonsware.com/office-hours/ once the chat is over
ming
yes I see. Thank you so much for your time!
Mark M.
you are very welcome
ming
has left the room
8:30 PM
Mark M.
turned off guest access

Tuesday, July 29

 

Office Hours

People in this transcript

  • Mark Murphy
  • ming