Office Hours — Today, December 12

Yesterday, December 11

Mark M.
has entered the room
Mark M.
turned on guest access
David
has entered the room
Mark M.
howdy, David!
how can I help you today?
David
Hi Mark!
Well, I'm fighting a PagerView + TabHost with Fragments, following this example: http://developer.android.com/intl/es/reference/...
Mark M.
David: do you have a question?
David
Yep, sorry, was searching for the link
Dec 12
7:30 PM
Mark M.
actually, that sample doesn't show TabHost anymore, IIRC
David
the question is: Is is possible to prevent the FragmentPagerAdapter from loading all the Fragments?
Mark M.
FragmentPagerAdapter will load three fragments at the outset, and the rest only as the user swipes
it will ensure that it has one fragment to each side after the first swipe, so it can handle the animations crisply
you can *increase* the number of fragments it holds onto, but you cannot decrease beyond three
David
Yeah, I noticed. The problem is that I'm using the same fragment for each page, only changing the arguments. I download json data and present a list. What is happening is that each one is trying to update the same list, and therefore everything crashes :)
Mark M.
"same fragment"? do you mean the same fragment *class*, or the same fragment *object*?
David
This is the first time I'm working with fragments, so I know my "solution" could not be the best. Or even right...
fragment class, sorry
Mark M.
then they can't be updating the same ListView, because each fragment object would have its own
David
so the problem must be elsewhere...
7:35 PM
Mark M.
either that, or you are not talking to the right fragments at the right time (e.g., you keep trying to update the first fragment)
Peri H.
has entered the room
David
the fragment starts requesting and processing data on "onActivityCreated", so I'm not even "talking" to the fragment
Mark M.
(BTW, howdy, Peri -- be with you in a moment)
Peri H.
thanks
Mark M.
David: how have you determined that "each one is trying to update the same list"?
David
Until now I was convinced that I was "sharing" the lists because I was retrieving the views by id, but as you said, each one has its own...
Mark M.
where and how are you "retrieving the views by id"?
are you calling findViewById() on the layout inflated by the fragment in onCreateView()?
David
on "onActivityCreated", like listView = (PullToRefreshListView) view.findViewById(R.id.live_scores_listview);
Mark M.
and where is "view" coming from in that code?
onActivityCreated() does not have a "view" parameter
is that from onCreateView()?
David
a reference from onCReateView
Mark M.
well, that seems OK
it would be bad if you were calling findViewById() on the activity
7:40 PM
Mark M.
as the activity will have several ListViews with the same ID, all coming from the same layouts
so long as you are scoping findViewById() to be from the fragment, then you should be working with independent ListViews
why don't you grab a stack trace showing your crash, and I'll take a question from Peri in the meantime
Peri: do you have a question?
Peri H.
Hi, yes.
Bye the way, I figured out how to deal with the Intent nesting.
The best solution, I think, was simply to unnest it and use a state variable at the parent level. Works fine now.
David
well, now that you mention it, I'll make sure every findViewById is called correctly...
Sure, I'll back with more info.
Peri H.
Today, I'm starting on my export function. I want to output xml and have never dealt with xml before. First off, I'd like to make sure I have character encodeing straight in my minde.
David
Thanks
Peri H.
If I understand correctly, what's most commonly used is UTF-8, right? Is that a 2 byte encoding that encompasses all possible chars in the world?
Mark M.
UTF-8 is the most popular encoding, though Wikipedia can probably give you a better formal definition for it than I can :-)
7:45 PM
Peri H.
Ok, I'll go back and read that. So, is it true that Java by default encodes all chars as UTF-8 and as well the android works that way?
Mark M.
Java doesn't do any encoding "by default"
certain Java *classes* might employ default encoding rules
but that would depend on the classes in question
Peri H.
Well, this is diverging from xml. But I need to understand this better first.
Mark M.
if you are generating XML, find a class/library that helps you and ensures the encoding is right, the escaping is right, etc.
Peri H.
What it really comes down to is text displayed to the user and user input.
Mark M.
neither of which are UTF-8 encoded, until they are perhaps written to a file or stream
Peri H.
When I define strings in the resource files, what do I need to do to make them UTF-8?
Mark M.
just type them, usually
Peri H.
I'm missing something. If I use my text editor to type them, everything is an 8-bit char.
Mark M.
not in any modern text editor
I've pasted 16-bit characters into things as weak as gedit on Linux for quite some time
now, something like Notepad might only use 8-bit ASCII encoding
these are questions for the people who are providing you with the tools and the classes that you are using
they aren't really Android development questions
Peri H.
Well, how about the eclipse editor? I use an external editor which (at least by default) displays 8 bit char, and evidentally the files are compatible between the two editors.
7:50 PM
Mark M.
AFAIK, the XML editors in Eclipse will save files as UTF-8 encoded
but that's a question for an Eclipse expert
Peri H.
Hmm. Ok, I look at the eclipse docs.
Mark M.
I am not an Eclipse expert, nor an i18n expert
Peri H.
So, back to xml.
Mark M.
hold on one moment -- let's give David another shot
Peri H.
I tried using the XmlSerializer, but found it too lame - in particular, it doesn't escape quote characters.
Mark M.
David: do you have another question, or a follow-up from your first one?
Peri H.
Ok, no problem.
Mark M.
hmmm... OK, no sign of David
Peri: back to you
I haven't written an XML file from Java in several years -- I do mostly JSON
but I presume there are other libraries for XML construction than the XmlSerializer
Peri H.
So, I decided to write my own xml writer.
Ok, you're not the person to ask about this. That's fine.
Next question.
I'm still vascillating on whether to use internal or external storage.
On early models, apparently internal storage was limited so people had to use external for large things.
Mark M.
correct
7:55 PM
Peri H.
Anymore (at least ver >= 4.0) is that an issue?
7:55 PM
Mark M.
no
pretty much everything made in 2011 and beyond will have 1GB or more of internal storage
and Android 3.0 pretty much eliminated a lot of the internal vs. external space issues
Peri H.
So, I can put as large a file as total space available will allow. There's no partitioning between internal and external?
Mark M.
on Android 3.0+, internal and external usually share a partition, and therefore share space
Peri H.
Ok, that answers that part.
Mark M.
on Android 1.x/2.x, internal and external were separate partitions
Peri H.
We talked about the benefits of internal vs external before.
Bascially, if it's internal, it hides it from most users - all those who have not "rooted" their device, right?
Mark M.
correct
Peri H.
That is desirable to me. (I wish I could protect from everyoine, but oh well). Are there any other advantages?
Mark M.
on Android 1.x/2.x, external storage was not always available
if the storage was mounted as a drive or volume on a host PC, Android did not have access to it
that too was corrected, after a fashion, in Android 3.0
Peri H.
Anything else, at least regarding 4+ ?
Mark M.
not really
Peri H.
Super. May I ask another question? David?
Mark M.
David: do you have another question?
David
Hi again, no more question right now
Peri H.
Ok, here goes.
Mark M.
OK, chime in if you think of one
David
ok
Peri H.
I'd like to do a ListView incremental search, just like the one for the Contacts app.
I've tried to figure out how to do this to no avail.
8:00 PM
Peri H.
Other than writing all of it from scratch.
Mark M.
what part of it have you had problems with?
there are a lot of pieces
Peri H.
There's something called a TextWatcher. During onTextChanged, I think I'm supposed to call adapter.getFilter().filter(s) where s is the text that changed. Nothing happens.
Oh, wiat, there was a preliminary part to this.
I don't understand how you get the search icon to appear.
Mark M.
the search icon in Contacts is an action bar item
Peri H.
Ok, so I need to add the search icon myself - it's not part of ListView?
Mark M.
or do you mean the icon to the left of "Find contacts" in the EditText?
ListView definitely does not have a search icon
Peri H.
The one in the action bar
Mark M.
on my Galaxy Nexus, the search icon is a simple action bar item, in the split action bar
@android:drawable/ic_menu_search, most likely
Peri H.
Ok, so then I should tie the TextWatcher to that search box, right?
Mark M.
what "search box"?
Peri H.
The EditText that appears when you tap the search icon (sorry to be vague)
8:05 PM
Mark M.
first, you will need to add that EditText (custom action bar nav, most likely)
Peri H.
Right, I understand.
Mark M.
that would be what you would tie the TextWatcher to, to find out about what the user types in
Peri H.
And then the rest is as I said above - call adapter.getFilter().filter(s) ?
Mark M.
I think so, assuming you have set up the filter already
Peri H.
Excellent! I'll try this out.
Mark M.
I don't have a sample for this, and it's been probably two years since I played with filtering a ListView
I'll make a point to try to add material on this to my book, probably for the early February release
Peri H.
If I get it working, I can send you some code if you like :)
Mark M.
something I should have done a while back
oh, that's OK, there's probably plenty of samples around
and I think I have a sample here somewhere, just gotta find it
(too much code, too little time...)
Peri H.
You would think. Didn't find any good ones, though.
I have one very brief question, if you still have time.
Mark M.
sure, ~20 minutes left in the chat
(David: again, if you come up with a question, jump in)
Peri H.
According to some google documentation, there are four recommended sizes for icons. I am using icons as buttons and, on the nexus 7, they are appearing at a reasonable size. If I follow this standard, will they be a reasonable size on all devices?
Mark M.
"According to some google documentation, there are four recommended sizes for icons" -- that depends entirely on the use of the icon
Peri H.
As a button.
8:10 PM
Peri H.
I want to be sure it is large enough to touch, but not much larger.
Mark M.
48dp is probably the right size for the button overall
Peri H.
I haven't seen this page. I guess I need to read it.
Mark M.
the button background will add some implicit padding
you'll have to experiment a bit
somewhere around 36dp is probably the desired size for the icon
Peri H.
Icons aren't declared in dp though. They're actual pixels. How do I experminet? I did try it on one other device (and it was ok).
I could make up various emulator configurations, but they might not be realistic.
Mark M.
the emulator should be OK, so long as you scale the emulator window to be an appropriate size
in terms of the icons, you get your pixels by converting dp to px
36dp = 36px at mdpi
Peri H.
Right, but I can invent any screen resolution I want and that might not be a realistic experiment.
Mark M.
36dp = 72px at xhdpi
the tools will guide you to common screen resolutions, densities, sizes
Peri H.
Ok, well let's just wait and see. It will probably be ok. I'll hear about it otherwise, I'm sure. :)
Mark M.
you put your icons in the appropriate density resource sets (e.g., res/drawable-hdpi/)
for whichever densities you wish to support
Peri H.
Yes, I did.
8:15 PM
Mark M.
then if you have done your calculations correctly, they should be fine, and you can use the emulators to basically confirm your theory
Peri H.
Alright, I'm done for today. Thanks so much.
Mark M.
you are very welcome
David
Ok, so now I'm pretty sure the problem is not what I thought :)
Mark M.
David: welcome to the joys of debugging :-)
Peri H.
has left the room
David
Haha, been there, but this is some "legacy" code and I think the network system was not ready for concurrent requests...
I'll have to chat with the previous developer tomorrow...
Thanks for your help, Mark
Mark M.
oh, OK
8:20 PM
David
If I get more weird errors, I'll come back ;)
bye!
Mark M.
bye!
David
has left the room
EGHDK
has entered the room
Mark M.
howdy, EGHDK!
how can I help you in the remaining 8 minutes of the chat? :-)
EGHDK
Hey Mark. I wanted to personally ask you this question, but I got stuck at work, but hope you don't get pissed if i just direct you to my SO question.
Mark M.
go ahead
EGHDK
I have to go soon (as do you), but I'd appreciate any advice. http://stackoverflow.com/questions/13839883/get...
Hopefully my question makes sense.
Mark M.
you really need to provide a stack trace, per the comment on the question
"causes it to crash" is not enough for anyone to really go on to give you a haned
er, hand
8:25 PM
EGHDK
Hahaha, okay, uhm so you have to realize I'm new to programming. So, even though I kinda know what stack trace means... I kinda don't.
hahaha
Mark M.
ah, OK
EGHDK
I know I get a StackOverflow error. lol
Mark M.
when you crash, a Java stack trace is written to LogCat
EGHDK
First time I've seen that.
Mark M.
you access LogCat as a view in Eclipse
EGHDK
Yes, I can read logcat pretty well.
Is the entire crash report (20 or so redlines) considered the stack trace?
Mark M.
probably
it will cite an exception, then a bunch of references to classes/methods/lines
EGHDK
Okay, so I'm looking for the exception, and everything after that.
Mark M.
yes
frequently, the stack trace will have one or more "Caused by" lines in the middle
you want all of that too
EGHDK
So stack trace = logcat error report.
Mark M.
well, stack trace is a Java concept
been around for 15 years or so
and is also seen in other programming languages
conversely, LogCat is used for a lot more than stack traces
EGHDK
Gotcha. Cool. Just making sure I get it right. It's hard to ask these kind of questions on SO or something lol.
Mark M.
yeah, I can understand that
I have a chapter in the book, relatively early on, that gets into some of this
EGHDK
Gotcha. I will post a stack trace later on tomorrow. Have to go back to work. I appreciate the clarification though.
Mark M.
"Debugging Crashes"
EGHDK
Yeah, fragmentactivities are a bitch.
But thanks again. I will gather some more questions for you for tomorrow possibly.
Take care
Mark M.
OK, tomorrow's chat is 10am Eastern
8:30 PM
EGHDK
Yep. I have an exam at 11, so I need to see if I'll be able to make it. Talk to you soon nonetheless. Night!
Mark M.
see ya!
EGHDK
has left the room
Mark M.
turned off guest access

Yesterday, December 11

 

Office Hours

People in this transcript

  • David
  • EGHDK
  • Mark Murphy
  • Peri Hartman