Skip to main content

Removing Completed Tasks

Lesson 15 from: Developing Android Apps with Java

Tony Hillerson

Removing Completed Tasks

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

15. Removing Completed 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

Removing Completed Tasks

it's forge on ahead. There's one more thing we need to do. We want to remove all completed tasks, so we're gonna do that by just having a button down here. Simple. Afford ins to remove the completed tasks will add a button at the bottom, and when that guy's clicked, will move. Will ask the adapter to remove all the tasks that air in the completed state, And that should be pretty simple to do, too. So to to accomplish that, we want to add a button to the main accidentally out, and when the button is clicked, will have the list adapter iterated through and remove all completed tasks. And then again, reflection refresh the list for you at the end. So in Maine, XML, I want to add another button. Um, things get a little bit more complex here because my, uh, button my remove but needs to sit next to this button at the bottom so I'm gonna paste in some code remove button. Here is the new button. We're adding. We want to remove content or I'm sorry, wrapped content on the Web, content to be th...

e attributes. We went a line parent bottom as well, and we want to use this new layout attributes layout to right of and that is gonna be laid out to the right of this ad button and the sting. The string is removed. Completed tasks all do that same. Factoring dance. Ah, just college. Remove complete. Give us some space. Select that. Go to re factor. Android extract Android string. Remove complete. That's what we want. Now that's in the strings file. Okay? And remember, the idea is removed button. So back in view tasks activity in set up views which you'll remember is called on create. We want to get a reference to that removed button as well, So just copy and paste this code and make the relevant changes. We'll call this remove button on the I. D. Is removed, but horror this at the field and then we want to set it on on click listener for that guy as well. And I can paste in some code to save some time here a the bottom set on close listener viewing clique, listener all that we're familiar with last week, um, we're gonna call this method, remove completed tasks, and that will be a protected method interview task activity so I can hover over here and have that completed. And it will show up down here just for housekeeping. I'm going to copy this or cut this and move it up here above set up views. Because it's so I like to have things organized. Okay? And now remove completed tasks. Um, what we want to do, there is just simply tell they'd adapter to do the work for us. So right. A method that we don't yet have cover over that create method, remove completed tasks in the task list adapter. And this is some just standard stuff that you can probably, um, guess that what we need to do is it rate over the list of tasks that we have, find which tasks are complete. Add that task to another list of task because the easiest way to remove some move, some set, are removed. Some set of data from another array list is to is to use this remove all method on a ray lists, which takes another a realist and the removes all items from the the second realist from the first a realist, and so that we're actually remove the tasks that are completed. But remember that we need to after that, tell all of the data providers their tell All of the any instances of components that are listening to this adapter is a data provider that the data set changed. So I think that should do it. Let me run it and give it a look and see if it's working. I had a couple tasks here. There's one thing I need to do. You could see there at the bottom the the buttons a little big. Now we got a couple tasks, which is useless, because now I have to restart the application anyway. So one problem here is this ad task button is a little too big. So I'm gonna come to Maine. So it's hide its hiding or other button. Yep. Okay. Yes. So this is a good, good indication are a good example of z order. So dizzy order of this task at task button. Um ah, that's weird, because it's defined below. You know what I think I could completely was wrong when I was talking about this. Really dizzy order is higher as the earlier it's defined in the in the file Okay, so I was wrong about that earlier in the class. So the these these items that are defined higher up in the file are actually at a higher Z order, which is the opposite of what I said at the beginning of the class. Sorry about that. But all we need to do to fix that it's a wrap content. Instead, instead of Phil parent, is it possible that dizzy order is Ah, as you stated. But ah, when you said Phil parent, it filled it to the lab all the way to the right to remove complete button is zero pixels wide right on the right hand side of the screen. Therefore, you can't see it. No, because once I have fixed that Phil parent, it works. The old l I see what I read. Felling your eyes up all the pixels. Yes, Yes, OK, I'm sorry. You're right. Good. That See, when I get scared, when my codes not working in front of however many people are online, I start to make up solutions that are incorrect. So I was right at the beginning of the class. Z order does go up as you define things. So What's your name? Bodily. Paul. Paul is Paul Saul. They're gonna give Paul a round of applause. He he saw through what was actually happening. So because add task was set to fill fill parent, it's it's with was set to fill parent. It spread out along this whole bottom part and remove complete was set to right of layout to right of add button. And there was no room for it to be laid out to the right. So it's over here in nowhere Land hanging off the side. And that's actually what was happening. Sorry. Got a little confused there, but Paul, straighten this out. Thanks, Paul. Okay, so now we have the button set up like we want, we'll add another task and we'll say, Thank Paul is complete because we just did that and we'll say, roof complete. Hey, works two minutes to spare. Yes. Sorry. Got a little. Rushed her at the end. But that really that middle, that middle one that took so much time, there really was a lot that we had to do before we could actually see some stuff, but hopefully it made sense. And if it didn't, we'll take some questions. And if those don't answer your questions of further review of the code should allow you to understand a little bit better and you can ask questions on the Forum and I'll I'll try to help out there. So that's what we've done so far.

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