Multi-Select List

Post Reply
User avatar
rbytes
Posts: 1794
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Multi-Select List

Post by rbytes » Wed Sep 26, 2018 1:39 am

Here is a way to use the LIST interface object to create a list from which you can make multiple selections. Just scroll and tap an item in the list to select it or unselect it.

Code: Select all

/*
Multi-Select List
by rbytes, September 2018
This is a technique I created several
years ago and have used in several of
my own programs. It allows you to select
multiple items from a list, instead of
just one item at a time.

Press to select an item. Press again
to deselect it. The output field will
display your choices.
*/
OPTION BASE 1
lf$=CHR$(10)       ' line feed character
GRAPHICS
GRAPHICS CLEAR .3,.3,.5
FILL COLOR .3,.3,.5
part$="⚪️ " ! part2$="🔘 "    ' emoji for 'unselected' and 'selected'
N$="mylist"        ' the selection list
O$="output"        ' text to display in the output field


'create a string array to store all listed items

DIM M$(10)
FOR t=1 TO 10
  READ item$
  M$(t)=part$&item$
NEXT t


' create list, field and labels

LIST N$ TEXT M$ AT 100,200 SIZE 400,300
FIELD O$ TEXT "" AT 550,200 SIZE 400,300 ML
FIELD O$ FONT SIZE 18
DRAW TEXT "MULTI-SELECT LIST" AT 425, 100
DRAW TEXT "CHOICES" AT 250, 170
DRAW TEXT "SELECTED" AT 700, 170


' The next 2 lines are part of the flashing attention-getter,
' and are not required for the list to work

DRAW TEXT "Tap or scroll list to select or unselect items" AT 270, 550
timevar=TIME()
dur=1.5


' main program loop

DO

' The next 9 lines are part of the flashing attention-getter,
' and are not required for the list to work

IF TIME()-timevar>dur AND first=0 THEN
  timevar=TIME()
  tog=1-tog
  IF tog THEN
    FILL RECT 269,549 TO 860,580
    dur=.5
  ELSE
    DRAW TEXT "Tap or scroll list to select or unselect items" AT 270, 550
    dur=1.5
  ENDIF
ENDIF


' the list mechanism

temp=LIST_SELECTED (N$)
IF temp<>-1 THEN
  first=1
  temp$=MID$(M$(temp),1,3)
  IF temp$=part$ THEN
    M$(temp)=part2$&MID$(M$(temp),4,50)
    GOTO skip
  ENDIF
  IF temp$=part2$ THEN
    M$(temp)=part$&MID$(M$(temp),4,50)
  ENDIF
  skip:
  LIST n$ SELECT -1
  LIST N$ TEXT M$
  out$=""
  FOR t=1 TO 10
    temp$=MID$(M$(t),1,3) 
    IF temp$=part2$ THEN out$&="  "&MID$(M$(t),4,50)&lf$
  ENDIF
  FIELD O$ TEXT out$
NEXT t
SLOWDOWN
UNTIL 0


' items for the list. If you add to them, increase the DIM value of M$

DATA "bananas", "bread", "butter", "cheese", "coffee", "cream", "lettuce", "milk", "peanut butter", "sugar"
Attachments
5426D61D-91C4-4370-9616-DCC233ECD7E3.png
5426D61D-91C4-4370-9616-DCC233ECD7E3.png (126.56 KiB) Viewed 1136 times
####### Living the colorful life #######

Post Reply