Office Hours — Today, March 11

Yesterday, March 10

Mar 11
3:45 PM
Mark M.
has entered the room
3:55 PM
Mark M.
turned on guest access
Andrey
has entered the room
rdg@rmcore
has entered the room
rdg@rmcore
hello
Andrey
Hello
Mark M.
hello, Andrey and rdg@rmcore!
4:00 PM
Mark M.
Andrey, I think you arrive seconds before rdg@rmcore
rdg@rmcore
Mark, I joined late last night.
Mark M.
so you get to go first!
rdg@rmcore
ok...I'll wait.
Mark M.
Andrey: do you have a question?
Andrey
okay
I have an activity that hosts a fragment with an EditText
What I need is to persist the contents in this EditText when I go to the second activity
and restore the text when I go back
I've tried several methods I found on Stack Overflow
but nothing has worked yet
I'm still a noob :)
Mark M.
you need zero lines of code for that
it happens automatically
hence, I'd focus on what you might be doing that is blocking your desired behavior
for example, have you overridden onSaveInstanceState(), in either the fragment or the hosting activity?
Andrey
no. I've only started overriding it trying to get auto-restore to work
Mark M.
then the text entered in the EditText should be kept
while the first activity is in the foreground, try rotating the device (portrait->landscape)
(or landscape->portrait)
this should cause your activity to be recreated
and your fragment to be recreated
if the text in your EditText is lost, then you have some problem in that activity and fragment
4:05 PM
Mark M.
if the text in your EditText is kept, then I'd focus on how you are starting up the second activity (e.g., are you calling finish() on the first one as part of that?)
run that experiment, while I take a question from rdg@rmcore, and I'll be back with you in a bit
rdg@rmcore: do you have a question?
rdg@rmcore
Yes. It is regarding the onclose listener of a search view for the action bar.
Other people have noticed the problem: http://stackoverflow.com/questions/9327826/sear...
But I can't understand the accepted answer.
from SO "Then override unimplents methods."
I don't know what the person is trying to say.
override unimplemnts methods?
Mark M.
well, setOnActionExpandListener() presumably takes an implementation of OnActionExpandListener as a paramater
er, parameter
that's an interface
which you will have to implement somewhere
and implementing that interface will require some methods
rdg@rmcore
ok.
Mark M.
presumably, onMenuItemActionExpand() and onMenuItemActionCollapse()
rdg@rmcore
ok....
so this is a different mechanism to call a function when the search view is closed by pressing the "X" button?
Mark M.
it's a general-purpose way to get control when collapsible action items are expanded or collapsed
SearchView is one such collapsible action item
presumably, onMenuItemActionCollapse() will be called when the SearchView is collapsed
rdg@rmcore
ok...so it is using methods from a parent class of SearchView?
ok
Mark M.
what is "it"?
4:10 PM
rdg@rmcore
hmm..let me rephrase
onMenuItemActionCollapse is a method in a parent class of SearchView?
Mark M.
no
rdg@rmcore
oh
Mark M.
it is a method on OnActionExpandListener
as I wrote, that is an interface
rdg@rmcore
so interface means an abstract base class?
(I am more familiar with C++ than Java)
Mark M.
no, interface means interface
rdg@rmcore
oh ok
Mark M.
interface is a separate Java construct
rdg@rmcore
ok...thanks.
I have another question about list views
it is related to this filter example from your book
let's say you have 25 items
Mark M.
hang on
rdg@rmcore
and then you start typing in the filter box
ok.
Mark M.
have to take a call for a few minutes, will be back shortly
rdg@rmcore
ok
4:15 PM
Mark M.
OK, I'm back
first, let's turn back to Andrey
Andrey: do you have a follow-up from your first question, or another question?
OK, Andrey, if you do have another question, let me know
Andrey
No Mark. I've just reinstalled the OS, so my app is just a bunch of text files at the moment. I think we will need to return to it next time
But
If I actually wanted to stop TextEdit from saving state
What could I do?
Mayb e it will give me some thought food :)
Mark M.
option #1 would be to not worry about it, but reset the EditText to your own starter value (e.g., "") when control returns to you (e.g., onResume())
option #2 would be to interfere with the onSaveInstanceState() handling
4:20 PM
Mark M.
doing that for everything in an activity or fragment is easy -- just override it and do not chain to the superclass
doing that for an individual widget would require some relying on some undocumented behaviors, and I would not recommend it
option #3 would be to extend EditText and interfere with how it participates in onSaveInstanceState(), but I don't know the details of how that would be done off the top of my head
those are the options that I can think of
rdg@rmcore: back to you
Andrey
okay, thanks a lot
rdg@rmcore
ok
so with a list view
let's say you have ten items
then you start typing in the filter box
and now the list view has 3 items
each item has an int postition and a string associated with it
let's say you click on the item in position 2
it becomes selected
then you hit the "X" in the filter box
now the item in the list view is at position 8
because you are back to a list with 10 itmes
items
I see there is a smoothScrollToPosition(int position)
the problem is I need to know the position of the item in the original list of 10 items
not just its position in the filtered list
in my current app I actually have a list view with over a thousand items
so the filtering is a really great feature
but when the "X" is pressed the list view scrolls all the way back to the top
4:25 PM
rdg@rmcore
so how do I know the item's position in the original list?
Mark M.
two things first
1. The row is not selected. It might be activated, if you're using that, but it's not selected, unless you're fussing with that yourself (and probably shouldn't).
rdg@rmcore
ok
Mark M.
2. I think the expectation is that if the user presses X that they're done with the filter results, and so I'm not convinced that what you're trying to do is necessarily the right thing. It might be -- I haven't thought it through much.
rdg@rmcore
on the screen in my app the item turns blue when pressed
Mark M.
if that sticks around, you're using the activated state
usually used on tablet UIs, in master-detail pattern
rdg@rmcore
yes....
I am using code derived from the master detail flow
Mark M.
there's nothing wrong with that, other than "activated" is a distinct Android concept than "selected"
rdg@rmcore
so when some selects an item from the large list all the details show up in another fragment
what happens is that the details don't match the activated item in my app right now
Mark M.
OK, then moving the list back to the activated row makes sense
what is the base class of your ListAdapter for the ListView? ArrayAdapter? CursorAdapter? BaseAdapter? something else?
rdg@rmcore
I am using an ArrayAdapter with an ArrayList<String>
this is from memory.
Mark M.
then you'll need to search your ArrayList<String> to find the new position
rdg@rmcore
I don't have the code in front of me
Yeah, I was afraid of that
like I said the ArrayList has over a thousand strings in it.
4:30 PM
Mark M.
there's another possibility that might work
rdg@rmcore
but if that is what is necessary
Mark M.
when the user taps on the entry in the filtered list, call getItemId() for the position in the filtered list
getItemId() is a method on your ArrayAdapter
rdg@rmcore
ok.
I will try getItemId()
Mark M.
never mind
ArrayAdapter is stupid
rdg@rmcore
no?
Mark M.
hang on a sec while I research something
rdg@rmcore
ok
Mark M.
there's probably a better solution than searching the ArrayList<String>, but I don't know off the top of my head what
rdg@rmcore
ok
Mark M.
Andrey: your turn -- do you have another question?
rdg@rmcore
I will take a look at the link.
Mark M.
(it's probably not what you need, but came up in a quick search)
4:35 PM
rdg@rmcore
Based on the link, I will need to review the getItem implementation.
Mark M.
rdg@rmcore: if you have another question, go ahead
rdg@rmcore
ok my next question is about moving sqlite select statements off the display thread
this is related to my master detail flow app
when an item is activated in the long list
I end up doing one select statement from a data base table
then I do another select statement in another data base table using the results of the first select
is some cases this takes longer than 1 second on my device
I have been reading your book and I am trying to decide whether to use an Async Task or to modify your https://github.com/commonsguy/cwac-loaderex
Mark M.
of those two, definitely use an AsyncTask
I'll be discontinuing CWAC-LoaderEx at some point
as I never use it
rdg@rmcore
the thing is I create my database ahead of time and it is treated as read only data during run time
oh
Mark M.
and the code is not very good
rdg@rmcore
ok...
4:40 PM
rdg@rmcore
thanks for the recommendation
I was leaning towards AsyncTask because I thought it might be simpler to implement
Andrey
has left the room
rdg@rmcore
I have another topic
Mark M.
go ahead
rdg@rmcore
how can I make clickable links in the about dialog of my app?
Mark M.
um
rdg@rmcore
do I need to tell it somehow that it is reading html text instead of just plain text?
Mark M.
what is "it"?
rdg@rmcore
sorry...
Mark M.
a TextView? a WebView? something else?
rdg@rmcore
textview
Mark M.
to show HTML in a TextView, call Html.fromHtml(), and pass the result to setText() on the TextView
fromHtml() supports a smattering of basic HTML tags, including <a>
rdg@rmcore
ok. cool.
Mark M.
rdg@rmcore
that is all I have
Mark M.
old, but it'll still give you a rough idea of the supported HTML tags
rdg@rmcore
thanks again for your code samples.
I used an example from the book of your unzip function
Mark M.
you are very welcome
rdg@rmcore
this allowed me to compress my database from ~12 MB to ~4 MB
Mark M.
do you mean SQLiteAssetHelper?
otherwise, I am not sure what you are referring to
rdg@rmcore
I could look again but I had the pdf open and searched for zip until I found the unzip code..
4:45 PM
rdg@rmcore
code starts on pg 630 o fthe book
Mark M.
it's a big book
I sometimes forget what's in it
rdg@rmcore
in tutorial #16
Mark M.
oh yeah!
I had forgotten about that
that's standard Java stuff
rdg@rmcore
I like the format of the book because it gives background discussion of the topics and then gives short examples.
The examples can be cloned from github.
This combination is really helpful.
Mark M.
yeah, I prefer focused samples more so than "everything but the kitchen sink" massive projects
rdg@rmcore
To read about a topic and have a working example.
I am not proficient in "standard Java stuff" so it is helpful.
thanks for your time.
Mark M.
you're welcome!
rdg@rmcore
how do I see the transcripts of these chat sessions?
Mark M.
they get posted a few minutes after the chat ends
rdg@rmcore
ok
Mark M.
and they go back years and years... :-)
rdg@rmcore
indeed.
ok. talk to you later.
bye
rdg@rmcore
has left the room
5:00 PM
Mark M.
turned off guest access

Yesterday, March 10

 

Office Hours

People in this transcript

  • Andrey
  • Mark Murphy
  • rdg@rmcore