May 29 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
tunneling | has entered the room |
tunneling |
hello Mark.
|
Mark M. |
howdy, tunneling!
|
Mark M. |
how can I help you today?
|
tunneling |
Let me start by telling you what I'm trying to do.. in case my approach is wrong you can stop me early.
|
tunneling |
I am creating an Activity for users to enter data.
|
tunneling |
The entry fields are dynamic, in that they are not known at compile time.
|
May 29 | 4:00 PM |
tunneling |
for simplicity, let's say they are provided in an XML file
|
Justin M. | has entered the room |
tunneling |
so for example.. i want to gather their: username, password, dob.
|
tunneling |
so i parse the xml file, then using a listview, create a list item for each of the required data
|
Mark M. |
(BTW, howdy, Justin -- be with you shortly)
|
tunneling |
so in my Activity layout, I have the ListView and a few buttons at the bottom.
|
tunneling |
my struggle is when i click the Save button, getting the data out of the EditText that are in the layout of the row
|
Mark M. |
why are you using a ListView, versus a ScrollView wrapped around a vertical LinearLayout?
|
tunneling |
as well as even entering data in the EditText.. the cursor seems to jump all over the placye
|
tunneling |
well, that's why I came here today.. wasn't sure if my approach was the best.
|
Mark M. |
I do not know what ListView is buying you here
|
Mark M. |
recycling won't help, as your rows will all be unique anyway
|
Mark M. |
and, ListView has its own thoughts on navigation and such
|
tunneling |
ok. makes sense.
|
Mark M. |
so, for example, the contacts data entry form is not a ListView (least, last I checked)
|
Mark M. |
even though it is somewhat dynamic, in that users can add fields
|
tunneling |
ah, good example.
|
May 29 | 4:05 PM |
Mark M. |
contrast that with a PreferenceFragment (or
classic PreferenceActivity), which *is* a ListView, but doesn't have
much in the way of directly user-mutable widgets, outside of CheckBox,
which plays well with ListView
|
tunneling |
right.. ok, good.
|
Mark M. |
in your case, I'd head down the ScrollView/vertical LinearLayout approach unless you have a compelling reason to do otherwise
|
tunneling |
no, I don't.. especially with the trouble I've been having even getting at the EditText data
|
tunneling |
thanks.
|
Mark M. |
Justin: do you have a question?
|
Mark M. |
OK, if either of you have a question, chime in
|
Justin M. |
Hi there, good afternoon :-)
|
Justin M. |
Yes, I do.
|
May 29 | 4:10 PM |
Mark M. |
Justin: fire away!
|
Justin M. |
I'm helping to advance the fragmentation of Android right now, but the good kind of fragmentation :-)
|
Justin M. |
Been working with fragments and so far am having good luck getting them to work...
|
Justin M. |
I just noticed a problem though on rotation where I lost the fragment stack when the device did a configuration change...
|
Justin M. |
I create the fragments dynamically and place them in a RelativeLayout placeholder in a single activity...
|
Justin M. |
I'm probably missing something obvious but how do I maintain my stack of fragments on a device configuration?
|
Mark M. |
it happens automatically
|
Mark M. |
that's what the FragmentManager does
|
Mark M. |
when you say "lost the fragment stack", what do you mean?
|
Justin M. |
I can explain...
|
Justin M. |
I have three fragments in the stack....
|
May 29 | 4:15 PM |
Justin M. |
Well, actually, I'm sorry that's not quite true...
|
Justin M. |
I start off with Fragment A, then replace it with
Fragment B. After a certain action occurs in Fragment B, I then execute
this code:
|
Justin M. |
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
Justin M. |
Because I don't want the first two fragments in
the stack anymore (they are no longer relevant because they are part of a
login process)
|
Justin M. |
After I pop the back stack, I add the "main screen' fragment, which displays fine...
|
Justin M. |
Until I rotate, and then I'm brought back to Fragment A being displayed again.
|
Justin M. |
Does that help explain or do you need some more detail?
|
Mark M. |
when you say "I start off with Fragment A", are you taking steps to not add it again on the configuration change?
|
Mark M. |
for example, if you always create Fragment A in onCreate(), that would explain matters
|
Justin M. |
yup, oops, that's what it is (knew it would be obvious) :-P
|
May 29 | 4:20 PM |
tunneling |
Mark, are these sessions meant to be interactive by all?
|
Justin M. |
What is a best practice then for getting the initial fragment loaded
|
Mark M. |
tunneling: what do you mean:?
|
Justin M. |
loading it in onCreate() doesn't look like a good idea then
|
tunneling |
i was doing something similar.. had some input.
|
Mark M. |
Justin: well, you need to know whether or not the login occurred, and conditionally add Fragment A in onCreate() based upon that
|
Mark M. |
tunneling: oh, go right ahead
|
tunneling |
View paste
|
tunneling |
i used a state machine approach, the save the state (ie fragment) to the bundle
|
Justin M. |
OK, I could try something like that. As far as
knowing the login state, I really didn't want the hosting activity to
have to be responsible for that logic. I just wanted to give it a
starting fragment and let the fragments keep track of that knowledge...
|
tunneling |
then in onCreate, pull the state out of the bundle and load that fragment
|
Mark M. |
Justin: well, *something* beyond a fragment presumably needs to know about the login state
|
Mark M. |
particularly if that fragment is going away via popBackStack()
|
Mark M. |
once you pop it, who knows if the user logged in or not?
|
Justin M. |
Yes, there will be business logic to handle that, so I suppose I could check that state and display based on that.
|
tunneling |
i use a viewless fragment and a service
|
Mark M. |
login state is part of your application state
|
May 29 | 4:25 PM |
Mark M. |
whether you hold it in a model fragment (what
tunneling referred to as a viewless fragment), or a static data member,
or a custom Application, is up to you and is somewhat dependent on who
all needs the data
|
Mark M. |
the model/viewless fragment only really works well if the scope is a single activity
|
tunneling |
Mark: I agree, that's why I use a Service as well. The model fragment binds to the service and request "connection status".
|
tunneling |
but I'm working with a persistant connection
|
Justin M. |
Gotcha. The app I'm working on is a kind of
complex situation where I'm just working on UI code and guessing on the
rest of the logic that another team is working on, so it's part of the
reason why I'm just saying it's business logic to determine if I'm
logged in or not. But anyways, I think I have a path to fixing the
problem now, so I'm all set. Thanks as always :-)
|
tunneling |
View paste
|
Mark M. |
"and guessing on the rest of the logic that another team is working on" -- oof
|
Justin M. |
Yeah, I know, I totally agree, this was not my choice :-(
|
tunneling |
Can I ask where their code exists or how it's implemented?
|
tunneling |
In the same app?
|
Justin M. |
Yes, it will be in the same app
|
tunneling |
As a Service or ...?
|
May 29 | 4:30 PM |
Justin M. |
yeah, i really can't go into much more detail about it, but there are services involved
|
May 29 | 4:30 PM |
tunneling |
just curious how your able to decouple the code
|
tunneling |
mark: i have another question.
|
Justin M. |
It's going to be a really big challenge, that's for sure :-)
|
tunneling |
I was curious because I am working on a project where I am doing something that sounds similiar
|
tunneling |
I have written an API document where I use Intents and aidl to communicate with the third-partys
|
tunneling |
anyways, can I ask my question?
|
Justin M. |
gotcha. I don't want to keep you from asking your next question. Go for it :-)
|
May 29 | 4:35 PM |
tunneling |
I have seen where some of the larger apps download
images, etc. Is there an elegant way to dynamically create layouts with
downloaded graphics?
|
Mark M. |
use BitmapFactory to load up the Bitmaps at runtime, wrap them in BitmapDrawables, and pop them into your UI
|
Mark M. |
(e.g., ImageView)
|
Mark M. |
or use the Bitmap objects directly if you are drawing to the Canvas
|
tunneling |
needs to be clickable
|
Mark M. |
anything is clickable
|
Mark M. |
ImageButton would show visual reactions to clicks, in the form of showing the pressed state of its background
|
tunneling |
ok. i need to read up on how to do that in code. i
created a custom button with all of the different graphics, but never
tried it in code.
|
tunneling |
* using xml and the background assignment *
|
Mark M. |
well, unless you are downloading the button
backgrounds themselves, you'd just create a new ImageButton object at
runtime and call setImageDrawable() or something
|
Mark M. |
or setImageBitmap()
|
Mark M. |
if anyone has questions, chime in
|
May 29 | 4:50 PM |
tunneling | has left the room |
May 29 | 5:00 PM |
Mark M. |
OK, that's a wrap for today's chat
|
Mark M. |
next one is Thursday, 10am Eastern
|
Mark M. |
have a pleasant day!
|
Justin M. | has left the room |
Mark M. | turned off guest access |