how to create blocks that will show image based on the value of label text?

224 views
Skip to first unread message

Xiaomy Redmii

unread,
Nov 11, 2018, 9:07:58 AM11/11/18
to MIT App Inventor Forum
I am just a beginner on MIT app inventor, I need your help guys. The value of the label text will come from a web server and will print an image based on a value of it.

TimAI2

unread,
Nov 11, 2018, 10:18:13 AM11/11/18
to MIT App Inventor Forum
You will need align the label text value with the name of the image.

Use an if/else block

If label1.text = poppy
set image1.picture = flower.jpg
else ....

Will the image also be on the server or will it be on the app ?

Taifun

unread,
Nov 11, 2018, 12:06:19 PM11/11/18
to MIT App Inventor Forum
I am just a beginner on MIT app inventor, I need your help guys

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  
How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the
 Top 5 Tips: How to learn  App Inventor

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.

Taifun

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



TimAI2

unread,
Nov 12, 2018, 11:51:51 AM11/12/18
to MIT App Inventor Forum
In answer to your private email:

it will be on the app / and the if label= 1(numbers) / what should I do if there are a lot of number? it's from 1-100 and each has image designated

The easiest way would be to name the images with the numbers e.g. 1.jpg, 2.jpg, 3.jpg

Then you can join the number from the server with the file extension

Otherwise create a csv with the numbers in one column and the filenames in the other, and use lookup in pairs

TimAI2

unread,
Nov 12, 2018, 6:15:51 PM11/12/18
to MIT App Inventor Forum
Please ask directly in the App Inventor support forum instead of sending me personal email. Your emails will be rejected.
That way other people can contribute to responding, and other people in the forum can benefit from the discussion.

Xiaomy Redmii

unread,
Nov 16, 2018, 1:48:31 AM11/16/18
to MIT App Inventor Forum
pls provide a sample block I still don't get it THanks

TimAI2

unread,
Nov 16, 2018, 6:49:10 AM11/16/18
to mitappinv...@googlegroups.com
A simple example of both methods as described above
I used a random generator to emulate the number coming from the server
If you choose to use a csv file, this could be a file in your assets, or called from a google sheet (for example)

BLOCKS

blocksnumberimage.png


SCREEN


screennumberimage2.png

screennumberimage.png



servernumberandimage.aia

Xiaomy Redmii

unread,
Nov 16, 2018, 11:06:53 AM11/16/18
to MIT App Inventor Forum
Thank you sir I'm trying :) it's a big help
my project is ranging a numbers with specific image / the random will work then? for example 0 - 5 is image showing full level and 6 -30 showing high level

TimAI2

unread,
Nov 16, 2018, 12:51:40 PM11/16/18
to MIT App Inventor Forum
The number generator was just there to create a number, you will use whatever method you choose to get your number from your web server

Xiaomy Redmii

unread,
Nov 16, 2018, 12:58:35 PM11/16/18
to MIT App Inventor Forum
the block is in random but in numbers I want to use a range how can I do that? my web server is 192.168.0.13 I will just initialize it

Xiaomy Redmii

unread,
Nov 16, 2018, 1:00:21 PM11/16/18
to MIT App Inventor Forum
the range I'm talking about is when 0-5 numbers will appear to text label coming from the web server the image will show is full and 7-30 is high and so on

Xiaomy Redmii

unread,
Nov 16, 2018, 1:01:45 PM11/16/18
to MIT App Inventor Forum
I can't find a block about range

Xiaomy Redmii

unread,
Nov 16, 2018, 1:27:22 PM11/16/18
to MIT App Inventor Forum
sir I can't connect it to the server and don't know how to range it pls help me again sir :(
I am confused

Xiaomy Redmii

unread,
Nov 16, 2018, 1:35:58 PM11/16/18
to MIT App Inventor Forum
I don't think I will use a random number because it will eat a lot of space in memory I prefer range (0-5 / 6-30 / 31-99 / 100-more)

Xiaomy Redmii

unread,
Nov 16, 2018, 2:19:26 PM11/16/18
to MIT App Inventor Forum
the server ip is 192.168.0.13
.

Xiaomy Redmii

unread,
Nov 16, 2018, 2:40:24 PM11/16/18
to MIT App Inventor Forum
please provide blocks :( I still not carry out my app on manipulating the data coming from the server :( 
and the range 0-5 is image for full / 6-30 image for high / 31-89 image for low / 90 - more is image for empty 
I tried to figure it out but can't have the exact solution for it :( 

Xiaomy Redmii

unread,
Nov 17, 2018, 1:50:30 AM11/17/18
to mitappinv...@googlegroups.com
I twist the idea into colors and finally got a new result but still don't get the exact solution / pls help me add the value from "generated value" to "image picked"

not working.png

Screenshot_20181117-144535.jpg


servernumberandimage (1).aia

Xiaomy Redmii

unread,
Nov 17, 2018, 2:19:04 AM11/17/18
to mitappinv...@googlegroups.com

Screenshot_20181117-151511.jpg

sad.png

I struggle on just single button the csv is error or my block is confusing?


servernumberandimage (2).aia

Xiaomy Redmii

unread,
Nov 17, 2018, 2:45:05 AM11/17/18
to MIT App Inventor Forum
help me pls I can't figure it out
xzc.png
servernumberandimage (3).aia

TimAI2

unread,
Nov 17, 2018, 4:59:50 AM11/17/18
to MIT App Inventor Forum
At the moment the global numberGenerated is empty (probably best to change the name of this to "serverValue"

Then in your web.gotText block set the serverValue(numberGenerated) value to the response Content, same as for label 4

Xiaomy Redmii

unread,
Nov 17, 2018, 5:13:00 AM11/17/18
to MIT App Inventor Forum
responseContent is not valid / but label4Text is valid I'm trying now

Xiaomy Redmii

unread,
Nov 17, 2018, 5:14:48 AM11/17/18
to MIT App Inventor Forum
csv is still in error

Xiaomy Redmii

unread,
Nov 17, 2018, 5:29:23 AM11/17/18
to MIT App Inventor Forum
sir pls help me I need to finish this :( 

Xiaomy Redmii

unread,
Nov 17, 2018, 5:46:58 AM11/17/18
to mitappinv...@googlegroups.com
I finally got it
but it doesn't show the image
try_me211.aia
Message has been deleted

TimAI2

unread,
Nov 17, 2018, 6:14:44 AM11/17/18
to MIT App Inventor Forum
From your aia try_me211  add the "lvl" to the file name when building the filename for the list of pairs

Xiaomy Redmii

unread,
Nov 17, 2018, 6:39:56 AM11/17/18
to MIT App Inventor Forum
where?? in the csv initialization??

Xiaomy Redmii

unread,
Nov 17, 2018, 6:45:07 AM11/17/18
to MIT App Inventor Forum
it works :) sir can I just do that in just one button??

Xiaomy Redmii

unread,
Nov 17, 2018, 6:53:46 AM11/17/18
to MIT App Inventor Forum
sir can you show me on merging those function in just one button / refresh the data coming from the server and follows the image

Xiaomy Redmii

unread,
Nov 17, 2018, 7:13:03 AM11/17/18
to MIT App Inventor Forum
Finally I solved it too

Xiaomy Redmii

unread,
Nov 17, 2018, 7:16:52 AM11/17/18
to MIT App Inventor Forum
but I need to twice click the button to change the image what to do sir?

Xiaomy Redmii

unread,
Nov 17, 2018, 7:19:19 AM11/17/18
to MIT App Inventor Forum
it's not appearing to change when you don't click it twice 
try_me212.aia

TimAI2

unread,
Nov 17, 2018, 7:42:58 AM11/17/18
to MIT App Inventor Forum
Your blocks need to be like this for that: (and these are the only blocks)

numbersandimageschanges2.png


Xiaomy Redmii

unread,
Nov 17, 2018, 7:46:10 AM11/17/18
to MIT App Inventor Forum
ok sir trying

Xiaomy Redmii

unread,
Nov 17, 2018, 8:03:59 AM11/17/18
to MIT App Inventor Forum
sir it works thanks !! 
but why when I left the app and back again (in short, exit)
the recent image and data becomes null (nothing display)? how can I set the recent data stay on the app?

Chris Ward

unread,
Nov 17, 2018, 8:35:48 AM11/17/18
to MIT App Inventor Forum
Hi

save the data to TinyDb and restore it when the App is re-opened.

Xiaomy Redmii

unread,
Nov 17, 2018, 8:41:53 AM11/17/18
to MIT App Inventor Forum
which data on the blocks sir?

Chris Ward

unread,
Nov 17, 2018, 8:30:06 PM11/17/18
to MIT App Inventor Forum
Hi Xiaomy

...the data that you want to retain :)

From the Help:

TinyDB is a non-visible component that stores data for an app.

Apps created with App Inventor are initialized each time they run: If an app sets the value of a variable and the user then quits the app, the value of that variable will not be remembered the next time the app is run. In contrast, TinyDB is a persistent data store for the app, that is, the data stored there will be available each time the app is run. An example might be a game that saves the high score and retrieves it each time the game is played.


Data items are strings stored under tags . To store a data item, you specify the tag it should be stored under. Subsequently, you can retrieve the data that was stored under a given tag.


There is only one data store per app. Even if you have multiple TinyDB components, they will use the same data store. To get the effect of separate stores, use different keys. Also each app has its own data store. You cannot use TinyDB to pass data between two different apps on the phone, although you can use TinyDb to shares data between the different screens of a multi-screen app.

When you are developing apps using the AI Companion, all the apps using that companion will share the same TinyDb. That sharing will disappear once the apps are packaged. But, during development, you should be careful to clear the TinyDb each time you start working on a new app.

Xiaomy Redmii

unread,
Nov 17, 2018, 10:05:44 PM11/17/18
to MIT App Inventor Forum
sir can you help me? about notification

Xiaomy Redmii

unread,
Nov 17, 2018, 10:06:09 PM11/17/18
to MIT App Inventor Forum
sir pls help me about notifications

TimAI2

unread,
Nov 18, 2018, 9:00:18 AM11/18/18
to MIT App Inventor Forum
What do you want to know about notifications ?

Xiaomy Redmii

unread,
Nov 18, 2018, 12:43:12 PM11/18/18
to MIT App Inventor Forum
the notification I did was a working app with notif when it is in build mode but the problem when I installed the app and then works but the notification is still not working

Xiaomy Redmii

unread,
Nov 18, 2018, 12:49:26 PM11/18/18
to MIT App Inventor Forum
I don't know why is it not working
Message has been deleted

SteveJG

unread,
Nov 18, 2018, 1:40:18 PM11/18/18
to MIT App Inventor Forum
Taifun answered this in your other post Xiaomy  (   https://groups.google.com/forum/#!category-topic/mitappinventortest/qiCstnj4mKM  ).   He said "does the example app work for you?
it might be, that the extension does not work anymore for newer Android versions..."

Most probably, the extension does not work in Android 8.1+ .   You are probably out of luck.  Try the example Taifun posted; if it does not work then Android 8.1 is the problem.  Currently there is not any way to fix this other than Taifun (or someone else) to create an extension that does work.

Regards,
Steve

Xiaomy Redmii

unread,
Nov 20, 2018, 6:58:05 AM11/20/18
to MIT App Inventor Forum
do you think a android 7 will work?
Reply all
Reply to author
Forward
0 new messages