Office Hours — Today, May 29

Thursday, May 24

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!
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.
I am creating an Activity for users to enter data.
The entry fields are dynamic, in that they are not known at compile time.
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.
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.
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
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
recycling won't help, as your rows will all be unique anyway
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)
even though it is somewhat dynamic, in that users can add fields
tunneling
ah, good example.
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
thanks.
Mark M.
Justin: do you have a question?
OK, if either of you have a question, chime in
Justin M.
Hi there, good afternoon :-)
Yes, I do.
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 :-)
Been working with fragments and so far am having good luck getting them to work...
I just noticed a problem though on rotation where I lost the fragment stack when the device did a configuration change...
I create the fragments dynamically and place them in a RelativeLayout placeholder in a single activity...
I'm probably missing something obvious but how do I maintain my stack of fragments on a device configuration?
Mark M.
it happens automatically
that's what the FragmentManager does
when you say "lost the fragment stack", what do you mean?
Justin M.
I can explain...
I have three fragments in the stack....
4:15 PM
Justin M.
Well, actually, I'm sorry that's not quite true...
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:
fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
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)
After I pop the back stack, I add the "main screen' fragment, which displays fine...
Until I rotate, and then I'm brought back to Fragment A being displayed again.
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?
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
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
tunneling: oh, go right ahead
tunneling
View paste
		// check to see if we have been here before
        if (savedInstanceState != null) {
            // Restore last state for checked position.
        	mInstallationStep = savedInstanceState.getInt("curState", 0);
        }
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
particularly if that fragment is going away via popBackStack()
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
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
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".
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
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        // save where we are in the process
        outState.putInt("curState", mInstallationStep);
    }
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?
In the same app?
Justin M.
Yes, it will be in the same app
tunneling
As a Service or ...?
4:30 PM
Justin M.
yeah, i really can't go into much more detail about it, but there are services involved
4:30 PM
tunneling
just curious how your able to decouple the code
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
I have written an API document where I use Intents and aidl to communicate with the third-partys
anyways, can I ask my question?
Justin M.
gotcha. I don't want to keep you from asking your next question. Go for it :-)
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
(e.g., ImageView)
or use the Bitmap objects directly if you are drawing to the Canvas
tunneling
needs to be clickable
Mark M.
anything is clickable
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.
* 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
or setImageBitmap()
if anyone has questions, chime in
4:50 PM
tunneling
has left the room
5:00 PM
Mark M.
OK, that's a wrap for today's chat
next one is Thursday, 10am Eastern
have a pleasant day!
Justin M.
has left the room
Mark M.
turned off guest access

Thursday, May 24

 

Office Hours

People in this transcript

  • Justin Munger
  • Mark Murphy
  • tunneling