Posts

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

Changing text size and color of spinner in Sketchware

Image
To change the text size and color of spinner dropdown list, follow the instructions given below. 1. In VIEW area of your Sketchware Android project, insert a Spinner spinner1 . 2. In LOGIC area, add a new String list list1 . 3. In onCreate event add items to the list. 4. After adding items to the String list, insert an add source directly block and put following code in it: spinner1.setAdapter(new ArrayAdapter (this, android.R.layout.simple_list_item_1, android.R.id.text1, list1) { @Override public View getView(int position, View convertView, ViewGroup parent) { TextView textView1 = (TextView) super.getView(position, convertView, parent); textView1.setTextColor(Color.RED); textView1.setTextSize(24); return textView1; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { TextView textView1 = (TextView) super.getDropDownView(position, convertView, parent); textView1.setTextColor(Color.RED); textView1.setTextSize(24); retu...

Share an image from an ImageView

To share an image from an ImageView in your Sketchware Android project, in VIEW area add a Button button1, which will act as a share button. In the event of on button1 click, use an add source directly block and put following code in it: Bitmap bm = ((android.graphics.drawable.BitmapDrawable) imageview1.getDrawable()).getBitmap(); try { java.io.File file = new java.io.File(getExternalCacheDir() + "/image.jpg"); java.io.OutputStream out = new java.io.FileOutputStream(file); bm.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (Exception e) { showMessage(e.toString()); } Intent iten = new Intent(android.content.Intent.ACTION_SEND); iten.setType("*/*"); iten.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new java.io.File(getExternalCacheDir() + "/image.jpg"))); startActivity(Intent.createChooser(iten, "Send image")); Now save and run the project. You should be able to share the image from imageview1.

Using TextToSpeech in Sketchware

Image
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 place so that it is...