Posts

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...

OptionsMenu in Sketchware

Image
In order to create OptionsMenu in Sketchware, follow the steps given below. 1. Create a more Block extra in your project. 2. To define this more block extra  use an add source directly block and put following code in it. } @Override public boolean onCreateOptionsMenu (Menu menu){ menu.add(0, 0, 0, "Item 1"); menu.add(0, 1, 1, "Item 2"); menu.add(0, 2, 2, "Item 3"); return true; } Note that here the first } closes more block. Rest of the code is outside the more block extra . This is to code for onCreateOptionsMenu where three items are added to the menu. Also note that 0, 1, and 2 are Id of the items added to the menu, and Item 1, Item 2, Item 3 are the title of the items added. Change the titles to whatever you want. To display the OptionsMenu items as icons on the ActionBar, add the id of the images to the menu items. Suppose ic_settings_white is the icon for item 1. Then the code above will change as below. } @Override pub...

Check for latest app version using Firebase in Sketchware

Image
You can store the latest version of your app in Firebase realtime database, and then check and compare it with the actual version of installed app. Follow the instructions below to know how to do this. 1. In your Firebase app in sketchware, in library manager, make sure you have entered correct App ID and project ID, and that Firebase switch is on. 2. Make sure the rules in your Firebase database are read and write true. 3. On the MainActivity or the Activity in which you want to check for the latest app version, add a new FirebaseDB component called Ver:version . 4. Create three new String variables, package_name ,  your_version and latest_version , and a new Map variable map . 5. In  onCreate  event, set the string  package_name  to package name of your app. 6. Next in onCreate, use an add source directly block and put codes for getting the version of presently installed app. try { android.content.pm.PackageInfo pinfo = getPackageManage...

DatePickerDialog in Sketchware

Image
To create a DatePickerDialog in Sketchware android project follow the steps given below. 1. In VIEW area of your sketchware android project, insert a LinearH and inside it insert a TextView textview1 , an EditText edittext1 and an ImageView imageview1 . For textview1 write text as ' Date: '. For edittext1 write hint as dd/mm/yyyy  and deselect 'enabled' in it's properties. 2. Choose image of a Calendar using image manager and set it as image of imageview1 . 3. Switch On AppCompat and Design. 4. Create a More Block showDatePicker . In this block, use an add source directly block and put following code. androidx.appcompat.app.AppCompatDialogFragment newFragment = new DatePickerFragment(); newFragment.show(getSupportFragmentManager(), "Date Picker"); 5. Create another More Block  extra.  In this put codes to define a DialogFragment. } public static class DatePickerFragment extends androidx.appcompat.app.AppCompatDialogFragment impl...