Skip to main content

Completing Tasks

Lesson 14 from: Developing Android Apps with Java

Tony Hillerson

Completing Tasks

Lesson 14 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

14. Completing Tasks

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

Completing Tasks

Okay, so now for completing tasks, this is actually a lot shorter. Um, all we want to do is whenever one of these guys is tapped when a list item is tapped, we want to talk about the state of the check box. So to do that, we want we need to implement a method that list activity gives us on on the list activity that we extended, which is called list on on lis. Item clicked. And then we already did this on task. We implemented a completed property. So now attached knows whether or not it's completed. And we will implement a toggle method which will allow us to Teoh easily toggle that state without knowing what state the task is in. And the list item view will mark the check, boss complete whenever a task is toggled. And then we will refresh the list to make sure that the that the freshest data is being displayed. So let's start with inside view task activity. We need to implement a method called on list item clicked, and that is again defined inside a list activity. It conveniently tells...

us whenever one of those is clicked, we don't have to do any sort of listening ourselves. Um, and we can get that easily implemented by going here. Toe source override implement methods on list activity we can look for on list item, click and click Check. Um, check box there. I want to put this after on resume and I click. OK, And now that code is automatically generated for me conveniently Ah, there's not really a lot of benefits to calling super there. Well, no, that's that's actually not true. We're going to make sure that we call super here. Um, because there's maybe some of the things that happen up the chain, so make sure you call super, um, And then let's, um, get the code that we want to be there. Taste that in here to avoid typing. So on the on the adapter, I'm gonna tell it to toggle the task complete, um, property at a position that is passed into us on the on lists and, um, clicked. So, um, so the position will be handled by the list view. It will tell us what position is collecting. We're gonna tell the adapter to toggle completeness of the task at that position, so I'm gonna come over over here, Create method toggle task completed position in task list adapter, and it will create that for us. And what we want to do here is get a task t equals tasks that get at position. Now, we have a reference to the task of that position and will say t dot toggle complete, which is a method that is not yet written. But it is easy to write by hovering over here and saying create method, taco complete and type task, And it will create that for me. And all we want to do is set complete equal to whatever it wasn't before the opposite of what it was before. And now we have a nice little way to toggle completeness. Um, but the next thing we want to do inside the adapter is after that, um, that completeness is toggled on a specific task. Once we save this, this shouldn't no longer be a problem. Why is it still complaining? Talk complete today. Save that. Yep. Public toggle complete. I'm just gonna say that this is a, uh not sure what the problem is there. Um but eclipse will come around to our way of thinking sooner or later. But after we ah, Otago the completeness of that task we want to say notify data set changed again because now something changed that only the adapter knows about so far. And we want to make sure that any any components that air listening or getting data out of this adapter are are up to date. Now in view task activity. We have a way to toggle the completeness of that of the task that has checked. And we'll run this guy and see that in action. No tasks again. And now when I click on it, I can talk about the completeness of the task. And it's reflected inside the check box. Yeah, what's the fun? I could sit here all day and click this, but I won't forge right ahead. Um, that was that was a nice short one. Was there any questions about what we did there? We have a couple. We have a question from the audience. Where did you listen at the list level and not at the item level? Because the list the list activity view task activity merely needed to go back to the adapter and say by the way, adaptor Let's see the always position end. You couldn't somehow have each view that adapter do it itself. Will the view the each row is made up of some little views. And you would think those views could, uh, handle their own toggling. Yeah, they probably could weaken, set up a listener here to see, um, inside the task list item view. We could set up some way of knowing whether or not it was tapped, and then check it. Um, there's no particular reason except that it's very easy. Teoh override on lists item clicked. And in a more complex application, this activity is probably the one that needs to know about, um I mean, so in this situation, all we need to do is change the the data on the model. Oh, if you were deleting example would be a little hard of each individual item to figure out the greater data structure to delete from or something. Right? Well, so I mean, in our situation, while you would do delete in a slightly different way, but in our situation yeah, the task needs to know that it to store it's complete value and the view needs to know to check off the check box. But the real meaning to the click is probably fairly interesting to the activity as well. So some things may happen here that, um the activity the few tests activity need to manage in later classes. Um, and in a more complex application, you may need to know about it up here. I don't know. That's that's That's something that, um, is maybe an implementation detail. And there's not really any benefit, except there's a heck of a lot less code I need to do inside the Thea This activity Teoh to figure out when something has clicked. I think the view and be a little bit more code. I don't know there's There's not a lot of benefit here, but in general the meaning of ah of a click is important at this point in the chain, too. I don't know if that's a good, good enough answer, given the application that we have, but I think that I'm doing something in here in the later versions of the class to

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