Use of List String blocks in Sketchware android projects
2 minute read
A string list is an ordered collection of strings, where user has precise control over where in list each string is added. Use of list blocks in Sketchware projects is described below.
Adding elements to list
Elements can be add to a list one by one, and they take the position as per the sequence in which they are added.
For example, if we add Google, Yahoo, Amazon, YouTube, and Android to a list, they will take positions 0, 1, 2, 3, and 4 respectively.
If a very large number of elements are to be added to the list, as in some kind of word game, then multiple more blocks can be used to add elements to the list, and the more blocks can be used in a sequence in the event where list is to be created.
The images below show an example.
An important aspect of lists is that they allow duplicate elements and they allow multiple null elements.
Using List elements in Spinner or ListView
Elements added to a list can be shown in Spinner or ListView by setting their data to the list, as shown in the images below.
a. Use of list in ListView
b. Use of list in Spinner
Use of individual list blocks
1. Add...to List String...
This block is used to add elements to a list, as described above.
2. Inset...at...to List String...
This block can be used to insert an element at a particular position in between a list. If an element is inserted at position 3, the previous element at position 3 will shift to position 4, and all other elements at later positions will shift to one higher position.
The blocks used in the image above will give following result.
3. Delete at...of List...
This block can be used to delete an element from a particular position in list. All elements at higher positions will then shift down by one position.
4. Get at...of List String...
8. Clear List...
Adding elements to list
Elements can be add to a list one by one, and they take the position as per the sequence in which they are added.
For example, if we add Google, Yahoo, Amazon, YouTube, and Android to a list, they will take positions 0, 1, 2, 3, and 4 respectively.
If a very large number of elements are to be added to the list, as in some kind of word game, then multiple more blocks can be used to add elements to the list, and the more blocks can be used in a sequence in the event where list is to be created.
The images below show an example.
An important aspect of lists is that they allow duplicate elements and they allow multiple null elements.
Using List elements in Spinner or ListView
Elements added to a list can be shown in Spinner or ListView by setting their data to the list, as shown in the images below.
a. Use of list in ListView
b. Use of list in Spinner
Use of individual list blocks
1. Add...to List String...
This block is used to add elements to a list, as described above.
2. Inset...at...to List String...
This block can be used to insert an element at a particular position in between a list. If an element is inserted at position 3, the previous element at position 3 will shift to position 4, and all other elements at later positions will shift to one higher position.
The blocks used in the image above will give following result.
3. Delete at...of List...
This block can be used to delete an element from a particular position in list. All elements at higher positions will then shift down by one position.
4. Get at...of List String...
This block gets an element from a particular position in list.
5. Index...in list string...
This block gets the position of an element. For example, if Yahoo is at position 1, index Yahoo in List String will return result 1.
6. List String... contains...
This block checks if a particular string is there in the list.
7. Length of List...
This block gets the number of elements in the List. It counts from 1 to the last element. Thus, length of list is one higher than the last position in list.8. Clear List...
This block deletes elements from all positions of the list.