i have a list of tasks, in which at a time only one task is running .i want t开发者_运维问答o show the running task at the top and completed tasks at the bottom and show the difference between them by using the seperator . how can i achieve this. please help me
Thanks in advance.
This really depends on how you're running tasks and how you're displaying a list (ListView I presume?). If you're running a task through something like an AsyncTask and a ListView, you should do something as follows:
- Make each item in the ListView represent a Task object (something you've created).
- Each Task object should have, in its class definition, a boolean flag that is initially false. This boolean flag will represent whether the Task is finished.
- Make sure that the Task object has a toString() method, since a ListView works by invoking the toString() method of each of its items. In your scenario, this will probably be a String representing the name of the Task.
- When the AsyncTask finishes its execution, set the boolean flag mentioned before to true.
- Have two ListViews that stack on each other with a bottom border for the top one (or top border for the bottom one). When a Task object's boolean flag is true, move it to the bottom (or top) ListView, depending on which ListView represents the "finished" list of Tasks.
I hope this helped. Not sure if this is the standard way to do it, but this is how I would do it off the top of my head.
精彩评论