Sort a list of text by a corresponding number

I'm creating an app that is essentially a to-do list but also automatically prioritizes user inputted task names by an algorithm based on the no. of days between today's date and the deadline date they select, the important of the task (1-10) and approximate time it will take to complete.

I want a list to display "task name | # days until due" but in order of the corresponding rankID from the algorithm based on integer values of task importance ans # of days until due. Right now I can display "task name | # days until due" without sorting or I can sort the inputs but only display the int that corresponds to the inputs. Any advice on how to sort by int but display str?

How to sort a list using the webviewer(!)
You also can sort list of lists using this method, see an example here.

and now you can even use the new WebViewStringChange event of the webviewer, which makes that solution even easier, for an idea how to do it see here

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

App Inventor will automatically display an integer as a string in a ListView.

I have a number of code snippets showing the manipulation of List View values (Items) on my website:
https://www.professorcad.co.uk/appinventorsnippets#EditListViewItem

Hi @Taifun, I tried the method you suggested. It seems to be changing the list to a csv row from the webviewer currentPageTitle. However, it is not changing the order in any way.

here is an image of my blocks:

@ChrisWard I was on that site last night looking for a solution. That's good to know that any ints in a list will be categorized as a string...thanks! However, from your site, I can see how to sort a list alphabetically, but I want to sort it by the first number (#) in the image above. "# | Task name | days until due"

it seems to be, you tried the simple sort example, which sorts a normal list...
you should follow the list of lists example, which is provided here https://groups.google.com/g/mitappinventortest/c/pVA3VUMN5W8/m/pZLttKYl3-8J

and as already mentioned, now you can use the new WebViewStringChange event, which makes that solution even easier, no need of using a clock component anymore...

Taifun

1 Like

Here is a blocks-only merge sort that has a customizeable comparison function you can fit to your table (list of lists) ...

After you sort your table, extract whichever Elements list you need for your display and selection process.

1 Like

Hi @Taifun, Thanks for your response! With your help and everyone else's I was able to figure out a way for the list to sort based on my values. However, when the strings return from sorting in webviewer, the formatting changes, creating a new row for each set of inputted data despite using the join statement. (images below explain this more clearly). Sorry to keep asking maybe simple questions but I am new at this and was wondering if there is a simple fix to this? I've tried various ideas but can not fix this issue. I also need the text to be displayed in a listview not a label so the user can select and delete each task individually, so change the type of display is not a good solution.
Any help is great!

Once you have sorted yout table (lists of lists), send it into an Elements value procedure (function) that returns a one dimensional list of Element strings for your ListView or List Picker, and set your .Elements to that output value.
After selection, use the SelectionIndex value as the index for a **select item from list ** against the sorted table, to get the row for the selected Element.
The row will be a list of column values you can select, according to how you laid out the columns of your table.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.