Skip to main content

Posts

Add ListView to Navigation drawer

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

Check for latest app version using Firebase in Sketchware

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

OptionsMenu in Sketchware

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. } @Ove...

Using TextToSpeech in Sketchware

To know how to use of TextToSpeech class in Sketchware, for reading the text from an EditText field, follow the instructions given below. 1. In your Sketchware Android project, and an EditText  edittext1 , and a Button  button1 . 2. In LOGIC area, in  onCreate  event, use  add source directly  block and in the block put the code given below. It should be the last block in onCreate event. t1=new android.speech.tts.TextToSpeech(getApplicationContext(), new android.speech.tts.TextToSpeech.OnInitListener() { @Override public void onInit(int status) { if(status != android.speech.tts.TextToSpeech.ERROR) { t1.setLanguage(Locale.UK); } } }); }android.speech.tts.TextToSpeech t1; private void nothing(){ This code initializes the TextToSpeech engine. It can speak only after initialization. If the user performs some other Activity after initialization, then it will not speak. It has to be initialized again for it to speak. So place this code again at appropriate p...

How to DELETE data from FIREBASE database from Sketchware app?

If you have an app which displays data from firebase database in a custom ListView, and you want to delete data from it, then follow this method. This method of deleting data is for apps which push data to firebase database on button click by using blocks as shown in image below, retrieves data from firebase database, on  Firebase DB onChildAdded  event, by using blocks as shown in image below, In order to delete data from this kind of app follow the steps given below. 1. Add a new String list  str . 2. In the CustomView, add an ImageView  imageview2  and set it's image to delete icon. On clicking this ImageView the item will get deleted. 3. In  Firebase DB onChildAdded  event, inside  Firebase DB... get children to List Map... then  block, add the block Add [childKey] to List String [str] , as shown in image below. This will create a list of keys or children at the DatabaseReference 'Chat'. 4. In the event  onBindCustomView  add th...

simple navigation drawer in Sketchware

In the latest version of Sketchware (v3.0.0), appcompat-v7 and design have been added, and we can now add a navigation drawer to our project. This navigation drawer uses a CustomView drawer_main.xml. In order to create a Navigation drawer, 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. Add items in the  linear1  of  drawer_main  and customize it to change it's look. 5. Create a new Intent component  i . 6. Now in the EVENT area, under section  drawer , add the events you want to execute (like  textview2 onClick ,  textview3 onClick , etc.). 7. Add codes to be executed in each of these events. 8. Save and run the project.

Firebase auth in Sketchware for Login Activity

To create a login activity using Firebase Auth in Sketchware, follow the steps given below. This method uses Firebase authentication service for creating login. 1. In your Firebase account, go to Firebase authentication. 2. In Firebase authentication web set-up, go to SIGN-IN method, and enable Email/password and Anonymous. 3. Go to Project settings in your Firebase project and copy the Web API Key, Project ID, and App ID. 4. Paste the Project ID, App ID, and Web API Key in your project in Sketchware, in the Firebase settings. 5. On the  MainActivity  page add a File Shared preferences component  user:user  and an Intent  i . Also add a Timer  t  and a Firebase Auth  testlogin . 6. Create a new page  login.xml  with Activity called  LoginActivity . 7. In  onCreate  event of MainActivity use blocks as shown in image below. It identifies main page with  File user key page . It also checks if user is logged in to  F...