Skip to main content

Displaying the Location of the Task

Lesson 31 from: Developing Android Apps with Java

Tony Hillerson

Displaying the Location of the Task

Lesson 31 from: Developing Android Apps with Java

Tony Hillerson

buy this class

$00

$00
Sale Ends Soon!

starting under

$13/month*

Unlock this classplus 2200+ more >

Lesson Info

31. Displaying the Location of the Task

Lessons

Class Trailer

Day 1

1

Overview: What is Android?

19:56
2

Eclipse and SDK setup and build a Red Flashlight app

38:05
3

Ad a button to a Green Flashlight

21:06
4

Add the Green Flashlight

18:48

Day 2

5

Week 1 - Layout and Build a Task Manager App

04:10
6

Displaying a list of tasks

40:44

Lesson Info

Displaying the Location of the Task

Okay. Now, the next thing we need to do is display the location that's attached the task on the items that you know, um, as a user, um, that you want to go to a certain location for that particular task, and then if if you we don't have a location on the task that we won't display it. Okay, um, to do that, we need to update load tasks in the application to retrieve the address in Latin long and then update the list item to conditionally display the address. If we have one switch back to the application. So low tasks is he's my little open trick. Here is where we select out all of the information that we want from the ah database and then display or put that into the tasks which will get displayed, um, coming out of the database. So we have to update the column list here, and let's do it in the right order, because order matters. We want the address off the task task address that we want task latitude and in the task, a longitude. So now we have three more columns coming out of this sel...

ect statement and to put them into the task. We want to do something like this After complete and line 47 I'll add. Um, see, this is this is the interesting thing. So it knows how to get a float out of of the the database. When I had everything working with an imager, he was turning as a float type. So I wonder how much resolution I was losing their cause. I got everything to work, I guess. Just the omission. Using the wrong data type, there wasn't enough to make things break. So I wonder how bad things actually were because those are the real tricky types of bugs where things seemed to work. Right? Um, in any case, now, we should have the right data type in the database and to put it on to the task, we just need to call the centers that we created down here and now all the task groups, all the tests that come out of the database are gonna have the address latitude, longitude set or no, or zero, depending on if they actually have those bits of information. And then those will be added to the current task list. All rights now after we do that, um, there's need to update the view here. And resource layouts. Ah, task list item. This is the the individual view that gets created for each task in the list. Uh, eclipse sometimes doesn't like strangely outs, but I don't know how what how this is that strange, but steams to not like that one. So I'm gonna switch over to the XML again. One more reason why don't really trust the visual view that often. And I just need to add one component here, a text view which will call address text. I'm gonna set the visibility to gone right off the bat. I remember that visibility is for actually not showing the component and also not not letting it figure into the layout of its parent. So that means that look back here in the in the presentation. You see that get milk list item is shorter than the visit Google list item, which is one nice feature of the Google of the android lists, actually makes variable list items are variable height list items pretty easy to deal with, which is harder and other languages and other frameworks. But now we have ah a text view, which is called address text, which we will use to to display that that address if there is one, and then that all happens inside task list item. So that is the class. Remember that. That, uh, uh, is instated for each item of the list. So open that task list item. There you go. Sure. This properties guy keeps popping up. Go away. All right, Tess. List item. This is the The classic controls the view. And when we say set task now, I'm gonna had at a little conditional statement here. If task has address than address text, I'll set the text and make the visibility visible. And otherwise, don't make the visibility gone. And you need to do this each time that you do this set task because remember each list item make it recycled, as as the user scrolls through the list, so it will have data on it at some point. So we need to make sure that we get everything in the right state, not just assume we're working from zero. Um, and then we need to make a field for address texts, which is just going to be the text veer. See? Yeah, the text. You if she just added into the view who? Okay, we'll find that the idea is our that I d dot address text. Do this import the rolled R. I think this might have imported the wrong. Are it reported? Android are We don't want that. We want our our which is calmed O'Reilly, that and road task manager dot Yeah. So now this are should work correctly. And we went our that I d dot address text, and then we also need to import view, and then we should be off to the races. So I run this and now Google What it starts over should sit load with the right address, and it should show up in the the task manager is having Whoa, look at that. What happened there for the size really blew up their wonder where that happened. So let's go figure out why that happened. I think that maybe I have to go check and see task list. Item is a linear layout. So some reason I set this up to be horizontal, I think I explain that last time because I was trying to create of you were um, the check box was next to a label. Um, or the check box was on the right, Aligned right on. The label was aligned left. But then I found that I could just use the checks text view, so orientation should be vertical. Some people? Yes, right. That's the long That's the long expedition. That's the short explanation. What I was trying to say Yes. So, um, once we make it vertical because it basically address is sitting off over here because we had the the layout horizontal. So this guy was getting laid out on screen and then taking up all the view and the text V was next to it. So this use it now, work correctly. That's the perils of pasting in code from partially from another application that I know works. All right, so there we go. Now, the address shows up nicely underneath. And if we just add a task like the old standby, get milk without a location, it shows up next with no location. So begin Android nicely deals with variable height list items, and now we're showing the address. Does anybody have any questions about that? Yes. I have some questions and we have a question in the audience. Let him ask first. Tony, I was worried about the reading from the database when there was Ah, no, let long defined, And you just put it in. Ah, primitive. So I was wondering if that get milk is gonna try to show a location. If you had shut down the app in and started up again because you can put zeros in your location and then it's no longer to be No, you know, of course, you were cut and paste, and so I wasn't falling on long if it was covered, but it seemed like you're gonna have a location of zero. Um, yes. Well, no, I won't have a location. Okay, so So where we're storing is not like some sort of location object. We're starting three pieces of data. The lat Long and the address. So the address is gonna be? No, because we didn't put in a string for that. And, yes, the let and long will both be zero. But that's fine, because I say, um, inside the, uh where is it? Well, test list item. Um, set task is where we decide to display and all we care about is whether or not it has an address and has address. If I hit F three here will jump to that code and that's just sees it, then addresses. No. So that should work. Fine. Um, let me see. I can fake out the emulator by just saving this hitting a space and saving it. Then it will think it's different. So it'll do a full deploy again, which means that it should start from zero and then load from the database again. So you should still see that there's no blank address there. Oh, it did order things differently this time. So does that answer your question? Yes, he says it does way. Have another audience question. Um, you're using three columns in the database to store the address, but the Google address implements parcel a ble, which I believe is a way of converting itself back and forth from a string. Could you have stored ah, the address in a single column in the database as it's parceled string form and then reconverted it back into a true address Object when you pulled it out? Yeah, I'm sure you could. And you could also use like a like the just the basic job serialize er to, um, Teoh, Turn that into a string. Um, but that's all the information that we need out of it. We could we could have done it that way. I think there's a lot more information. Well, there may have been more information that we didn't need. This is enough for our purposes, but yeah, that's way of doing it. Okay? And I have a couple questions, and then Ruth has some questions to, um somebody asked, How do we get the corrected address from Google? So you've been spilling amphitheater without an H. Apparently, you need an extra age. And so if you do misspell, But Google is able to find it anyway. Oh, I see that it did that. All right. Yeah. So that's that's not the one I typed in. That's the one Google gave me. So yeah, it's filter right. I have also been spilling. I don't even know if their spellings the weird things. Let's we can have a whole other screen cast on spelling where where I preach about spelling and and other pedantic people can correct me. But I also spelled with an e r instead of a nari. But it apparently changed it to an R e e. They didn't change it. It found it by some sort of, ah, method of saying, Well, this is actually with the guy meant basically, when you you entered the location, it returns. The the first thing that it finds that matter, right? Yeah, I remember. We've got a really dumb search algorithm that just gets the 1st 1 that Google gives us back blindly. Um, if there was no results than we don't even really handle that case, but yeah, then it would be That would be an indication that we really can't spell. Okay. Okay. So I have, Ah, a couple of questions here. Uh, if I select a visit Google task, Does it display them at page? No. Would that be a good exercise for the viewer? Okay. Uh, and it automatically filled in the zip code for Google's address. Apparently, I believe so. Yes. And finally, why do items in the database get reordered? Sometimes I don't have any contacts with us. It just popped up suddenly. Um, let's look at the order statement. They have first of all, let me go back to the one who said, Ah, if you select it, will it show the map right now, we're using select to mean complete. So you'd have to rethink how we do that. User interaction. Um, that's just a just something else to to think about. Um Ah, let's go back and answer the 2nd 1 by looking at the application where we actually pull it out of the database I ordered, by task complete and then task name. This is the order by string which gets turned into this and sequel. So, um, since the name get milk is alphabetically before get visit Google, it shows up first. But I didn't do the ordering when I When I add a new task, Does that make sense? Yes. Thank you. I have another question. Is it also possible to get a business name for a given address? Um, I think, um, so I think that is in the later version that somebody on the forums had a problem where they weren't getting any results back for where they were searching. And I looked into it just a little bit, and I found that there was a bug in an earlier version of the Geo locator or use either a bugger enhancement. I wasn't sure. Um, where they where Google actually came down on that. But I think it's now implemented. Better Will. You can search businesses near a certain location, so, yes, I think I was fixing August. That bug with my particular bug was fixed in August.

Ratings and Reviews

a Creativelive Student
 

I thought everything on this site was free and now they want 99 dollars for a course

a Creativelive Student
 

very good

Student Work

RELATED ARTICLES

RELATED ARTICLES