Making the lines in a multiline text box the text in a list of buttons

190 views
Skip to first unread message

SPL

unread,
Nov 16, 2016, 9:28:58 AM11/16/16
to MIT App Inventor Forum
I have three buttons, call them A, B, and C (their current text is nothing) a button (call it ADD) and a multiline text box OR every item in a comma separated list (1,2,3, etc). This is what I want:
When I press button ADD that buttons A, B, and C take the name of the lines in the list :
1
2
3

(or 1,2,3 if CSV)

So that button A is renamed 1, B = 2 and C = 3. 

Possible? Been sitting all afternoon.

Taifun

unread,
Nov 16, 2016, 9:30:19 AM11/16/16
to MIT App Inventor Forum
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

Taifun

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

SPL

unread,
Nov 16, 2016, 1:06:38 PM11/16/16
to MIT App Inventor Forum
So, what I'm trying to do is this:

1: When I add something (ONE LINE) in the text box, then press ADD, the first button gets that text. Second time (ONE LINE), the second button gets the text and the third time (again, one line) the third button gets the text. It works until the third button. What am I doing wrong? Is there an easier way?

2. If I copy MULTIPLE (3) lines in the textbox and press ADD I want the lines to get the text from the different lines. So if the textbox has the text:
1
2
3

If I then click ADD, I want the buttons to get the numbers 1, 2 and 3 in order. Do you understand?
Texttobutton.aia
blocks.png

Abraham Getzler

unread,
Nov 16, 2016, 1:07:52 PM11/16/16
to MIT App Inventor Forum
Change your 1,2,3 or 1\n2\n3 into a list by using a split block.
set buttonA.Text to select item 1 from list x
set buttonB.Text to select item 2 from list x
set buttonC.Text to select item 3 from list x

See Books and Tutorial section of this FAQ:

ABG

SPL

unread,
Nov 16, 2016, 2:34:42 PM11/16/16
to MIT App Inventor Forum
Can you please help me once more? I am a total beginner. So, I managed to do this: When ADD.longclick set button A,B,C text to a,b,c respectively (see picture)

What I have no clue about how to do is to make a new list x from the textbox with , or \n and select the index from the list. 
blocks.png

Abraham Getzler

unread,
Nov 16, 2016, 3:11:00 PM11/16/16
to MIT App Inventor Forum
See the How to Work with Lists section of the FAQ I mentioned.
ABG

SPL

unread,
Nov 17, 2016, 12:56:33 AM11/17/16
to MIT App Inventor Forum
Thanks! That was really helpful.

 So I've come this far now, any help would is appreciated. I still don't know how to make the split block list, can't find anything in the tutorials and I don't understand the built in help. See attached files.
blocks (1).png
Skärmbild_2016-11-17_06-52-16.png
Texttobutton.aia

Taifun

unread,
Nov 17, 2016, 8:10:03 AM11/17/16
to MIT App Inventor Forum
use Do it to debug your blocks, see tip 4 here

it seems to be, you are working with a list of lists instead of a simple list
each bracket pair represents a list...

SPL

unread,
Nov 17, 2016, 10:17:53 AM11/17/16
to MIT App Inventor Forum
Thank you for the DoIt help and I'm sorry for making another thread.

From the PDF you provided I got some answers. I still can't figure out how to make the multiline text different items in the list, but maybe someday I will.

Taifun

unread,
Nov 17, 2016, 10:27:27 AM11/17/16
to MIT App Inventor Forum
you might want to provide a new screenshot of your relevant blocks including Do it results 
and a short description of the issue: how the result currently is and how it should be

Taifun

Abraham Getzler

unread,
Nov 17, 2016, 11:25:58 AM11/17/16
to MIT App Inventor Forum
See attached for how to do the split.
You were wrapping the list that came out of the split block with an extra layer of list wrapping, that threw off the selects.

The Line Feed character is \n and you can do the same split as you did on a comma on a Line Feed to get a list.

ABG

Skärmbild_2016-11-17_06-52-16.png

SPL

unread,
Nov 17, 2016, 1:01:50 PM11/17/16
to MIT App Inventor Forum
Thank you sooo much, it works!


SPL

unread,
Nov 17, 2016, 1:46:53 PM11/17/16
to MIT App Inventor Forum
Is there any way I can have both , and \n? If I have both, neither work.

Abraham Getzler

unread,
Nov 17, 2016, 2:27:10 PM11/17/16
to MIT App Inventor Forum
Is there any way I can have both , and \n? If I have both, neither work

There's a text block that can replace all \n with commas.
But think of a way to control your input better, so you don't have to deal with both.

On the other hand, is it possible you are being presented with a table when you get both , and \n ?
 If so, look at the csv-to-table block to turn it into a list of lists, if that's what is the shape of your data.

Maybe show us what the data looks like?
ABG

SPL

unread,
Nov 17, 2016, 3:20:27 PM11/17/16
to MIT App Inventor Forum
The app is supposed to be a grocery list, where the user puts a list of his/her groceries in the text box and the it generates buttons with each of the item as text. As I can't know if the user separates the items with commas or a new line, I want the option to be both :)

Abraham Getzler

unread,
Nov 17, 2016, 4:01:24 PM11/17/16
to MIT App Inventor Forum
Use the replace all text block to change the Newlines to commas,
and run it thru a split at commas.
ABG

SPL

unread,
Nov 17, 2016, 9:39:05 PM11/17/16
to mitappinv...@googlegroups.com
Oh, that's smart. Let me try!

THANK YOU! WORKS LIKE A CHARM!

SPL

unread,
Nov 19, 2016, 4:32:57 AM11/19/16
to MIT App Inventor Forum
Hey, Taifun, can you merge threads? I want to ask continuing questions, but don't want to start new threads all the time. Can you merge this and my other one into a new one called SPL's Shopping Cart App or something?

Ghica

unread,
Nov 19, 2016, 7:24:28 AM11/19/16
to MIT App Inventor Forum
We do not like threads that are very long or that are about multiple subjects, because it is difficult to see when something is answered ans to search through the forum for a specific thing. Of course you can start a thread called SPL's Shopping Cart App and ask anything in it. Taifun will usually complain when he thinks subjects diverge too much.
Cheers, Ghica.
Reply all
Reply to author
Forward
0 new messages