Mar 11 | 3:45 PM |
Mark M. | has entered the room |
Mar 11 | 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!
|
Mar 11 | 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
|
Andrey |
I have an activity that hosts a fragment with an EditText
|
Andrey |
What I need is to persist the contents in this EditText when I go to the second activity
|
Andrey |
and restore the text when I go back
|
Andrey |
I've tried several methods I found on Stack Overflow
|
Andrey |
but nothing has worked yet
|
Andrey |
I'm still a noob :)
|
Mark M. |
you need zero lines of code for that
|
Mark M. |
it happens automatically
|
Mark M. |
hence, I'd focus on what you might be doing that is blocking your desired behavior
|
Mark M. |
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
|
Mark M. |
while the first activity is in the foreground, try rotating the device (portrait->landscape)
|
Mark M. |
(or landscape->portrait)
|
Mark M. |
this should cause your activity to be recreated
|
Mark M. |
and your fragment to be recreated
|
Mark M. |
if the text in your EditText is lost, then you have some problem in that activity and fragment
|
Mar 11 | 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?)
|
Mark M. |
run that experiment, while I take a question from rdg@rmcore, and I'll be back with you in a bit
|
Mark M. |
rdg@rmcore: do you have a question?
|
rdg@rmcore |
Yes. It is regarding the onclose listener of a search view for the action bar.
|
rdg@rmcore |
Other people have noticed the problem: http://stackoverflow.com/questions/9327826/sear...
|
rdg@rmcore |
But I can't understand the accepted answer.
|
rdg@rmcore |
from SO "Then override unimplents methods."
|
rdg@rmcore |
I don't know what the person is trying to say.
|
rdg@rmcore |
override unimplemnts methods?
|
Mark M. |
well, setOnActionExpandListener() presumably takes an implementation of OnActionExpandListener as a paramater
|
Mark M. |
er, parameter
|
Mark M. |
that's an interface
|
Mark M. |
which you will have to implement somewhere
|
Mark M. |
and implementing that interface will require some methods
|
rdg@rmcore |
ok.
|
Mark M. |
presumably, onMenuItemActionExpand() and onMenuItemActionCollapse()
|
rdg@rmcore |
ok....
|
rdg@rmcore |
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
|
Mark M. |
SearchView is one such collapsible action item
|
Mark M. |
presumably, onMenuItemActionCollapse() will be called when the SearchView is collapsed
|
rdg@rmcore |
ok...so it is using methods from a parent class of SearchView?
|
rdg@rmcore |
ok
|
Mark M. |
what is "it"?
|
Mar 11 | 4:10 PM |
rdg@rmcore |
hmm..let me rephrase
|
rdg@rmcore |
onMenuItemActionCollapse is a method in a parent class of SearchView?
|
Mark M. |
no
|
rdg@rmcore |
oh
|
Mark M. |
it is a method on OnActionExpandListener
|
Mark M. |
as I wrote, that is an interface
|
rdg@rmcore |
so interface means an abstract base class?
|
rdg@rmcore |
(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.
|
rdg@rmcore |
I have another question about list views
|
rdg@rmcore |
it is related to this filter example from your book
|
rdg@rmcore |
let's say you have 25 items
|
Mark M. |
hang on
|
rdg@rmcore |
and then you start typing in the filter box
|
rdg@rmcore |
ok.
|
Mark M. |
have to take a call for a few minutes, will be back shortly
|
rdg@rmcore |
ok
|
Mar 11 | 4:15 PM |
Mark M. |
OK, I'm back
|
Mark M. |
first, let's turn back to Andrey
|
Mark M. |
Andrey: do you have a follow-up from your first question, or another question?
|
Mark M. |
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
|
Andrey |
But
|
Andrey |
If I actually wanted to stop TextEdit from saving state
|
Andrey |
What could I do?
|
Andrey |
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())
|
Mark M. |
option #2 would be to interfere with the onSaveInstanceState() handling
|
Mar 11 | 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
|
Mark M. |
doing that for an individual widget would require some relying on some undocumented behaviors, and I would not recommend it
|
Mark M. |
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
|
Mark M. |
those are the options that I can think of
|
Mark M. |
rdg@rmcore: back to you
|
Andrey |
okay, thanks a lot
|
rdg@rmcore |
ok
|
rdg@rmcore |
so with a list view
|
rdg@rmcore |
let's say you have ten items
|
rdg@rmcore |
then you start typing in the filter box
|
rdg@rmcore |
and now the list view has 3 items
|
rdg@rmcore |
each item has an int postition and a string associated with it
|
rdg@rmcore |
let's say you click on the item in position 2
|
rdg@rmcore |
it becomes selected
|
rdg@rmcore |
then you hit the "X" in the filter box
|
rdg@rmcore |
now the item in the list view is at position 8
|
rdg@rmcore |
because you are back to a list with 10 itmes
|
rdg@rmcore |
items
|
rdg@rmcore |
I see there is a smoothScrollToPosition(int position)
|
rdg@rmcore |
the problem is I need to know the position of the item in the original list of 10 items
|
rdg@rmcore |
not just its position in the filtered list
|
rdg@rmcore |
in my current app I actually have a list view with over a thousand items
|
rdg@rmcore |
so the filtering is a really great feature
|
rdg@rmcore |
but when the "X" is pressed the list view scrolls all the way back to the top
|
Mar 11 | 4:25 PM |
rdg@rmcore |
so how do I know the item's position in the original list?
|
Mark M. |
two things first
|
Mark M. |
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
|
Mark M. |
usually used on tablet UIs, in master-detail pattern
|
rdg@rmcore |
yes....
|
rdg@rmcore |
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
|
rdg@rmcore |
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
|
Mark M. |
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>
|
rdg@rmcore |
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
|
rdg@rmcore |
Yeah, I was afraid of that
|
rdg@rmcore |
like I said the ArrayList has over a thousand strings in it.
|
Mar 11 | 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
|
Mark M. |
getItemId() is a method on your ArrayAdapter
|
rdg@rmcore |
ok.
|
rdg@rmcore |
I will try getItemId()
|
Mark M. |
never mind
|
Mark M. |
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. | |
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)
|
Mar 11 | 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
|
rdg@rmcore |
this is related to my master detail flow app
|
rdg@rmcore |
when an item is activated in the long list
|
rdg@rmcore |
I end up doing one select statement from a data base table
|
rdg@rmcore |
then I do another select statement in another data base table using the results of the first select
|
rdg@rmcore |
is some cases this takes longer than 1 second on my device
|
rdg@rmcore |
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
|
Mark M. |
I'll be discontinuing CWAC-LoaderEx at some point
|
Mark M. |
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
|
rdg@rmcore |
oh
|
Mark M. |
and the code is not very good
|
rdg@rmcore |
ok...
|
Mar 11 | 4:40 PM |
rdg@rmcore |
thanks for the recommendation
|
rdg@rmcore |
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
|
Mark M. |
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.
|
rdg@rmcore |
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?
|
Mark M. |
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..
|
Mar 11 | 4:45 PM |
rdg@rmcore |
code starts on pg 630 o fthe book
|
Mark M. |
it's a big book
|
Mark M. |
I sometimes forget what's in it
|
rdg@rmcore |
in tutorial #16
|
Mark M. |
oh yeah!
|
Mark M. |
I had forgotten about that
|
Mark M. |
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.
|
rdg@rmcore |
The examples can be cloned from github.
|
rdg@rmcore |
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.
|
rdg@rmcore |
I am not proficient in "standard Java stuff" so it is helpful.
|
rdg@rmcore |
thanks for your time.
|
Mark M. |
you're welcome!
|
rdg@rmcore |
how do I see the transcripts of these chat sessions?
|
Mark M. | |
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.
|
rdg@rmcore |
ok. talk to you later.
|
rdg@rmcore |
bye
|
rdg@rmcore | has left the room |
Mar 11 | 5:00 PM |
Mark M. | turned off guest access |