-2

I am just wondering if a toast activity could print out a text taken from an online database (google spreadsheet or google doc) at random? using JSON maybe?

Here is my code and right now it's just displaying random text but from the bank which I have provided in the code...

String[] toastMessages = new String[] {"text1", "text 2", "text 3", "text 4"};
                int randomMsgIndex = randomnize.nextInt(toastMessages.length);
                Toast.makeText(getApplicationContext(), toastMessages[randomMsgIndex], Toast.LENGTH_LONG).show();
            }

Many Thanks!

Jagmaster
  • 107
  • 4
  • 12

1 Answers1

0

Yes you can display any string using toast !!

Akshay Panchal
  • 695
  • 5
  • 15
  • Hi @Akshay and thanks for your confirmation. Please help me how to put it in code application. I've made a simple google spreadsheet (public and published) [link](https://docs.google.com/spreadsheets/d/e/2PACX-1vRIqpP_NVo5sONjbS20LrgH_mOLd5LakgHoVMFFCnbANLayHx9n8NXFCikz54AuuI3kzlNjl5Nprrz3/pubhtml) So lets say I want the toast to print out the message as well as the name corresponding to that text in 'text-name' format like 'Hello-A' and 'Good morning-D' many thanks! – Jagmaster Dec 01 '16 at 04:30
  • Do it like this Toast.makeText(getApplicationContext(),message+"-"+subject, Toast.LENGTH_LONG).show(); – Akshay Panchal Dec 01 '16 at 06:47
  • Hi @Akshay. First of all thank you for helping me out I really appreciate it. Hmm I am still confused (sorry I am fairly new to coding). 1. How would the code know which source to get the string resource from? I am going to give the link to my friends and they can edit the 'message' entries so the button assign to it will call out random entries 2. I think I am going to have to put the identity of the source somewhere inside 'new String[] {"text1", "text 2", "text 3", "text 4"};' so that the code knows where to pull data from right? Many thanks! – Jagmaster Dec 01 '16 at 09:44