Posts

Create a simple quiz app using Json in Sketchware

Image
To create a simple quiz app using Json String in Sketchware, follow the steps given below. 1. Create a json array containing all the questions and options. Each object in the array should contain a question with key ' ques ', four options for the question with keys ' a ', ' b ', ' c ' and ' d ', and the correct answer with key ' ans '. [ { "ques" : "The larynx in adults lies in front of hypopharynx opposite the...", "a" : "second to fifth cervical vertebrae", "b" : "fifth to seventh cervical vertebrae", "c" : "third to sixth cervical vertebrae", "d" : "first two cervical vertebrae", "ans" : "c" }, { "ques" : "Which of the following is the largest cartilage of larynx?", "a" : "thyroid cartilage", "b" : "cricoid cartilage", "c" : ...

Sort Firebase data for Android project

Image
If your firebase data contains same keys at each position, as shown in image below, then you can follow the steps below for sorting the data before displaying it in an app created in Sketchware. 1. In your Sketchware project, add a ListView listview1 . 2. Create a CustomView custom.xml . In this View add TextViews for displaying data at each position in Firebase database. 3. In properties of listview1 select custom.xml as customView. 4. Add a new List Map  maplist . 5. Add a FirebaseDB component with any name, and with data location same as in your Firebase database. ( fdb: results ) 6. Add ListView onBindCustomView event. In this event use blocks for displaying the data from List Map  maplist  in ListView listview1 . 7. Save and run the project. 8. Delete the installed app. 9. Export source code of this project. Unzip it in a folder on sdcard. 10. Open the project in AIDE. 11. In app level build.gradle  file, in dependencies, chang...

JSON syntax

Image
JSON syntax rules Data is in name/value pairs "My name"   :   "Sanjeev" Data is separated by commas { "name" : "Sanjeev" , "age" : "29" , "registration number" : "1628634" } Curly braces hold objects { "name" : "Sanjeev", "age" : "29", "registration number" : "1628634" } Square brackets hold arrays [ { "name" : "Sanjeev", "age" : "29" }, { "name" : "Ranju", "age" : "25" }, { "name" : "Anand", "age" : "16" }, { "name" : "Richa", "age" : "20" } ] A name/value pair consists of   a field   name or key   (in double quotes), followed by a   colon , followed by a   value . {   "name"   :   "Sanjeev"   } Types of Values in JSON In JSON,   values   must be one...

Loading images in WebView in Sketchware

Image
We can use WebView for loading images from any url or for loading images from drawable folder, assets folder, or resource folder of our app. 1. To load an image from a website in WebView, we can directly write the url of the image in the WebView loadUrl block. Even animated gifs can be loaded directly to WebView. WebView   webview1   loadUrl   http://.....jpg 2. We can modify the width and height of this image loaded in WebView by using following code in  WebView loadUrl  block: WebView   webview1   loadUrl   data:text/html,<img width=100% height="" src="(imageUrl)"> We can make it fit the width of the screen by setting width=100% in above code. 3. We can also load the images added using Image Manager in Sketchware (images in drawable folder) with following code: WebView   webview1   loadUrl   file:///android_res/drawable/image Note that in above code image is name of the image and has to be changed acc...

How to load limited items from Firebase into ListView

Image
If your Firebase database contains lots of items and you wish to load only limited items from it, so that it loads faster, then you can make use of Firebase Query . To load limited items from Firebase database, follow the steps given below. 1. Add a ListView listview1  and a TextView textview1 in VIEW area. 2. Create a CustomView custom.xml.  This should contain as many TextViews as data to be displayed at each position (let them be textview1 , textview2 , textview3 ). 3. Select custom .xml as the CustomView of listview1 . 4. Add a FirebaseDB component specific to the firebase path you have in your database. I have added FirebaseDB component Chat: chat   where chat is the path in firebase database, and Chat is a DatabaseReference to created in the app to the Firebase path chat. 5. Add a new number variable limit . 6. Add a String list str and a Map list map1 . 7. In onCreate event: a. Set the number variable limit to 6 (or to the number ...

Add ListView to Navigation drawer

Image
In the latest version of Sketchware (v2.2.2), appcompat-v7 and design have been added, and we can now add a navigation drawer to our project. This navigation drawer uses a CustomView. But the CustomView in Sketchware doesn't have option to add a ListView. In order to add a ListView to the drawer, we have to create the ListView programmatically and then add it to the drawer. To know how it can be done follow the steps given below. 1. In your Sketchware android project, go to Library manager and switch on AppCompat and Design. 2. In View manager , go to MainActivity.java and select Navigation Drawer Activity . 3. Now go to the CustomView drawer_main and add a LinearV linear1 . Set it's width as MATCH_PARENT. 4. Create a new String list mylist . 5. Create a new Intent component i . 6. Now suppose you have five other activities SettingsActivity.java , NotesActivity.java , FeedbackActivity.java , PrivacyActivity.java , and AboutActivity.java . Add a w...

Display a list in a Dialog Box in Sketchware

Image
To display a list of items in a Dialog Box in Sketchware follow the steps given below. 1. In your Sketchware android project, add a Button button1 and a TextView textview1 . The Button is for showing Dialog Box and TextView is for displaying the selected item. 2. Now go to LOGIC area, and add a List String list . 3. In onCreate event, add items to the list. 4.  Create a new Dialog component dialog . 5. In Button onClick event use the Block Dialog setTitle , to set the title of the Dialog Box. 6. After that use an add source directly block and write following code in it. dialog.setAdapter( new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, list), new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface _di, int _pos){ textview1.setText(list.get(_pos)); }} ); 6. After the above code in Button onClick event, add Dialog show block. 7. Save and run the project. On clicking the button you will see a...