Home Blog Page 65

viewFlipper in android studio – Image Slider example using view flipper

viewflipper android
viewflipper android

Hi Guys, Welcome to Proto Coders Point, In this android tutorial we will learn & implement android viewFlipper with example.

What is viewflipper in android?

ViewFlipper in android is a layout view that accept more then one view (like Imageview,TextView or any other layout vew) but display only one view at a time & thus we can use viewflipper to transition from one view to another with proper animation effect while switching smoothy between view in view flipper.

In Android, view flippers are mostly used as automatic image slider in android androidhive, the easiest way to show image slider to the app users.

android ViewFlipper Example

image slider using viewflipper android

Note: Android viewFlipper & ViewSwitcher both work same but the difference is:
viewSwitcher: can’t home more then 2 view child.
viewFlipper: can hold two or more child view at a same time.

Basic ViewFlipper XML code Example

In below xml snippet code you see i have view Flipper that has 3 view as a child of it, you can add as many view you want to flip.


       <!-- You can add as many view you want to flip -->
       <!-- I have created 3 TextView under viewFipper -->
           android:text="This is TextView 1"/>

           android:text="This is TextView 2"/>

           android:text="This is TextView 3"/>


Steps to Implement ViewFlipper in android

Time needed: 2 minutes

Below i step by step process to adding view flipper android

  1. Create View Flipper reference

    create a reference object of view flipper class by using findViewById().

    ViewFlipper viewFlipper = (ViewFlipper) findViewById(R.id.ViewFlipper1);

  2. Declare Animation object

    Then Declare 2 Animation object using Animation Utilities & LoadAnimation default Animation effect.

    Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
    Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);

  3. Set in-Animation

    Now set In-animation to flipper using viewflipper.setInAnimation(in);


  4. Set Out-Animation

    Now set out-animation to flipper using viewflipper.setOutAnimation(out);


  5. set timer to change view

    set the flip Interval timer to change to next view.

    viewFlipper.setFlipInterval(3000); //in millisecond

  6. finally

    Use autoStart or manually startFlipping


Let’s look into some useful Method of ViewFlipper

Here are some view Flipper method that are used to manage the vie

1. startFlipping(): Start the timer to cycle through view flipper child views, you can call this method on events such as button click or some other event.
Eg: Start cycler of view flipper android

ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
viewFlipper.startFlipping();   // start the view cycle

2. stopFlipping(): used to stop flipping of child view, when we no longer need to see the flip view of the child layout. call stop flipping method on button press or any other event.


ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
viewFlipper.stopFlipping();   //stop it 

3. setFlipInterval(milliseconds): The time before switching to next child view in milliseconds.

Eg: as you see we have set the flip interval to 2 second : 2000 milliseconds before switching to next view.

ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
viewFlipper.setFlipInterval(2000);  //interval of 2 secends

or you can set Interval directly through xml


4. setAutoStart(boolean): This method will automatically call startFlipping() method. when the app loads.


ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);

or else directly start from xml using autoStart


5. isAutoStart(): used to check if the viewflipper is in autoStart mode. This return boolean type value either true or false.
it is true if the view get automatically start else return false.

ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
            // if true
            // if false

6. isFlipping(): used to check if viewFlipping is flipping or no. This method returns either true or false


ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
Boolean isFlipOn = viewFlipper.isFlipping();

7. showNext(): used to manually switch to next child view of viewfliper on some event like button pressed.


 ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
 btnNext.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
               viewFlipper.showNext(); //go to next child view on button click

8. showPrevious(): used to go back to previous child view

Eg: when button press go back to previous child view

 ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);
 btnPrevious.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
               viewFlipper.showPrevious();  // go to previous child

9. LoadAnimation(context,anim effect id): Used to define a Animation effect using AnimationUtilities.


       // Declare in and out animations and load them using AnimationUtils class
        Animation outAnim = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
        Animation inAnim = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);

10. setInAnimation(inAnim) & setOutAnimation(outAnim): used to set Animation effect to viewflipper which switching between child.

       // set the animation type to ViewFlipper

11. addView(View child): Using addView you can easily add new child view to viewFlipper at RunTime of your android app dynamically.


       ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.simpleViewFlipper);

        TextView t1 = new TextView(this);
        t1.setText("This is Set text addview view flipper example");
        ImageView imv2 = new ImageView(this);

        //adding new view at runtime to viewflipper

Complete Source Code on ViewFlipper in android


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


        android:textStyle="bold" />



package com.example.viewflipper;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewFlipper;

public class MainActivity extends AppCompatActivity {

    private ViewFlipper simpleViewFlipper;
    Button btnNext;
    //array list of images from drawable
    int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5,R.drawable.image6};     // array of images
    ImageView imageview;
    protected void onCreate(Bundle savedInstanceState) {
        btnNext = (Button) findViewById(R.id.buttonNext);
        simpleViewFlipper = (ViewFlipper) findViewById(R.id.viewFlipperId);

       //create imageview view and add the view to viewflipper
        for(int i = 0;i<images.length;i++){
            imageview = new ImageView(this);

        // Declare in and out animations and load them using AnimationUtils class
        Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
        Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);

        // set the animation type to ViewFlipper

        // set auto start for flipping between views

        btnNext.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                // show the next view of ViewFlipper

output – android viewFlipper Example

viewflipper image slider
View Flipper android

Animation using Flutter Lottie animations

flutter lottie animation example

Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial we will talk about a flutter package called ‘Lottie‘ that helps us to load animation files that are in JSON format.

A Lottie animation – for flutter

The Lottie is a website that provides some free animation image files in JSON format that we can add in our flutter application to display pre-built animation like ‘Lottie animal crossing’ as shown below.

lottie animal crossing

A Lottie is a pre-built Animation that is in JSON format, For the JSON file, we can simply add it in our flutter assets folder & use them to display Lottie animation in the flutter app.

The Flutter Lottie is a package library that parses Adobe After Effect animation file exported in JSON file & renders them natively on mobile device app.
It works greatly and smoothly on Windows, Web, Linux, iOS, and Android Devices.

Video Tutorial

How to install/add flutter Lottie package in flutter project

1. Add lottie dependence

In your flutter project you will find a file by name pubspec.yaml open it and under dependencies section add the library.

  lottie: ^1.0.1

after adding new dependencies just click on pub get button

2. Import the lottie dart file

Now once you have added the lottie dependencies now you can use it anywhere in your flutter project.

then, to use it you just need to import lottie.dart package in your dart file.

import 'package:lottie/lottie.dart';

3. Download animated json file from Lottie files website

Now Visit https://lottiefiles.com/ and download your choice json animation file from lottiefiles.com

4. Create a Assets folder to store lottie animation json file

Now create a new flutter assets folder in your project and give the access to it in pubspec.yaml so that your flutter project can access the folder

if you are new to it refer below screenshot

Then as you can see I have created the folder ‘ assets/lottieJSON/….’ in which I have copied the downloaded json animation file from lottiefiles.com and then in pubspec.yaml file i have added the file path to the assets directory.

5. Snippet code to use Lottie widget flutter

Load json animation from assets folder

                width: 200,
                height: 200,
                fit: BoxFit.cover

Loading animation json file from network URL

Here is a url of lottie moon christmas offering json animation

                width: 200,
               height: 200,
              fit: BoxFit.cover

Loading animated json file from zip file

                width: 200,
                height: 200,
                fit: BoxFit.cover

Output of above Lottie widget

Flutter Logger – How to print log messages in flutter.

how to log in flutter
flutter logger library

Hi Guys, Welcome to Proto Coders Point, In this flutter tutorial we will cover flutter logger & how to log data in a flutter to help developers in debugging & improving projects for long-term maintenance.

Please note that in this flutter tutorial we will not cover logging in file or logging to remote service.

What is Logger – flutter?

A logger object is used to log/show messages on the IDE console Logcat window.
In Flutter, logging is the most important & useful feature provided that helps developers track, trace, find out the error log & debug logger error.

How to var log message in flutter?

Generally logging messages in flutter can be done using 2 ways

1. Using stdout & stderr

Generally printing a message on the console screen is done using the print() method by importing ‘dart:io’ & by invoking stdout & stderr.


         stdout.writeln("This log is using stdout");
         stderr.writeln("This log is using stderr");

Output on Console

Using Print() method Example

print("This Message using Print method");

Suppose, the log message or error log message is long the android just ignores some of the log & print only half of it, In that case you can use ‘debugPrint()’ it will print whole list of log data error.

2. Other is using ‘dart:developer” log() function

This allows developer to include a bit more information in logging output messages.

So to use developer.log function in flutter print to console or devtool, you need to just import ‘dart:developer’ as devlog & now use it as shown below ( devlog.log(“This is Log message from developer log method”); )

import 'dart:developer' as devlog;

void main() {
 devlog.log("This is developer log func message",name:'MyLog');

output: developer.log console log will only be show in devTool

So now you have seen above log method are default dart logs
Here i have found out best flutter logger library that help in printing different kind of logs on console.

Best Flutter Library to log message on console

Flutter Logger Library

Flutter Logger library is very helpful for developer because it help usin printing log message on console n beautiful format.

We all use default log messages to print some statements on the console, as shown above, but they get missed & are difficult to find & might not even see them.

How to use flutter logger library

Learn more obout Logger from Official site

1. Add dependencies

Open pubspec.yaml > under dependenices section add logger: ^1.0.0

  logger: ^1.0.0  #version might change
2. Import the logger dart class

Then to make use of logger flutter you need to import the logger.dart file where you are going to use them.

import 'package:logger/logger.dart';
3. Creating instance of logger class & Printing on the console

default logger instance

  final logger = new Logger();

Custom logger instance

Logger in flutter takes some of the properties that you can customize how your logger message will be displayed on the console screen.

final logger = new Logger(
    printer: PrettyPrinter(
      methodCount: 1,
      lineLength: 50,
      errorMethodCount: 3,
      colors: true,
      printEmojis: true

Then now once your instance of Logger is been created now you can use the instance object name to print log on console, as shown below

          logger.v("Verbose Log");
          logger.d("Debug Log");
          logger.i("Info Log");
          logger.w("Warning Log");
          logger.e("Error Log");
          logger.wtf("What a terriable failure log");

There are various kinds of log message that you can use to print on the console such as Verbose log, Debug Log, Info Log, Warning Log, Error Log, as shown in the above snippet code.

Outputflutter logger example

Logger Example – flutter

Flutter Null Safety example – handle null exception

null safety in flutter
null safety in flutter

Hi Guys, Welcome to Proto Coders Point, so in this flutter tutorial blog article, will learn about flutter null safety with example.

What is null safety in dart?

A Flutter Null Safety feature is a secured way of developing a flutter application, In any programming language, a variable can have a value assigned to it or might be null.

// Eg: Snippet 

String name;  // is null
String firstname = "Rajat Palankar";  //has a value been assigned.

because in dart variable can be null & if a variable is null we cannot perform an action with it like, printing the null value on user screen or we cannot execute at string method to a null value & if we do so this may lead to null pointer exception & your flutter application will crash in run-time.
As shown in below Code and output Screenshot

Example without null safety flutter


// Snippet Flutter Dart code 

class _MyHomePageState extends State<MyHomePage> {
  String name;  // null value
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text(name),   // trying to print null # run time , null pointer exception

Output example

Here you can see that when i tried to print null in text widget it showing Failed assertion – A non-null string must be provided.

flutter app without null safety

Flutter null safety enable

To solve null pointer exception flutter 2 came with null safety feature.

Set the minimum sdk constrant to 2.12.0 or higher & also check you have updated flutter version(flutter 2)

Then, if you want to use null safety dart then you need to enable null safety to do so, in your flutter project go to

Flutter Project > pubspec.yaml file

change sdk version >= 2.12.0

  sdk: ">=2.12.0 <3.0.0"   

and run flutter pub get

So now you have successfully enabled null safety in flutter project, now all of our datatype are by default “Not Nullable”

Not nullable means they requires some value to be assigned to them. A String, Int, or any date type must have some value.


int number = 15;

String name = " Proto Coders Point";

What if you want some datatype to be nullable

If in case, you want to make a datatype to be nullable then you need to add a question (?) mark to the datatype.

so in the above example, just by adding ‘?’ immediately after the data type, you can make it nullable which means Null is allowed.

Flutter null Safety Examples

  1. Null Safety Example 1
flutter null safety example
Null safety Example

Late Modifier to achieve null safety

Example without late modifier which gives you null safety error.

String name;   // null safety error
  void initState() {

    name = "Rajat Palankar";

The above code will give you a null safety compilation error because dart is not clever enough to understand that you have initialized the value to the variable afterwords.

Therefore, to future initialization or late initialization value to variable you can make use of “late modifier”, that tells compiler that value will be initialized later on.

what is late modifier?

In Flutter late keyword will lets you use non-nullable datatype. Now i dart 2.12 has add late modifier, late keyword is used in two case:

  • While migrating flutter project to null safety.
  • Lazy initializing of a variable.

Late keyword is used just to promise dart compiler that you are going to intialize the value to variable later on in future.

Note: if you don’t full fill as promised using late modifier then your flutte app will crash at runtime.

Late modifier example

late String name;  // here I am using late keyword before datatype to tell the compiler that I will initialize the value later

  void initState() {

    name = "Rajat Palankar";   // as promised initializing is done here 

    print(name);   //now i can use the variable

Instance Variable in java – with java Program Example

instance variable in java with example
instance variable in java with example

Hi Guys, Welcome to Proto Coders Point, In this tutorial we will discuss on what is instance variable java with an example.

Instance Variable java definition

An instance variable is declared in a class just outside the method, constructor, or block of code.

Basically, Java Instance Variable gets instantiated/created when an object of a class is created & destroyed when the object is destroyed. So we all know the class definition: An object is an instance of a class & every object has its own copy of the instance variable.

Point to remember about java instance variable

  1. Instance variable can be accessed only by creating an object.
  2. No need to set the value to an instance variable, by default “0” is set for number, “false” is set for boolean datatype & “null” is for object references.
  3. These are non-static variables.
  4. They are declared inside class just outside method, constructor & block.
  5. using the “new” keyword, when the object is created the class instance variable will also get created & when the object is destroyed even the instance variable gets destroyed.
  6. Initialization of class instance variable java can be done by using class object name as shown below.
Person p1 = new Person();

p1.name = "RAJAT PALANKAR";  //initialization value to variable

Instance Variable Java Example

class Person{
    //instance variable of class
    String name;
    int age;

public class Main
	public static void main(String[] args) {
		//creating person1 Object
		Person p1 = new Person();
		p1.name="RAJAT PALANKAR";   // initializing value
		//creating person1 Object
		Person p2 = new Person();
		p2.name="RAM PALANKAR";
		//display data of person 2
	   System.out.println("Data of person 2");

In above java code, example on instance variable, we have 2 variable in class person i.e. name & age. I have create multiple object by name p1 & p2, each object has it own copies of variable instance values.


Data of person 2   
RAM PALANKAR                                                                                                                  

Introduction to java programming

Types of variable in java

Best laptop for programming – Android studio requirements 2021

Best laptop for programming
best laptop for programming android development

Hi Guys, Welcome to Proto Coders Point, This Blog is about the best laptop for android development to run an android studio on a laptop smoothly.

So, you are planning to buy a new laptop for programming, if yes, then you are in right place, here we will share the best laptop for programming a guide to help you choose the best laptop specification for android studio.

When it comes to android studio development requirements you need to analyze laptop configuration carefully to run android studio smoothly before buying the laptop.
That’s because android studio & Emulator if runs at once it consume lots of RAM & processor load.

Laptop configuration for programming to run Android Studio smoothly

best laptop for android development or flutter development

Here are some specification need to been note before deciding which laptop is best for programming.

1. SSD Storage not HDD:-

I personally suggest you to buy a laptop which had SSD Storage as primary storage where you need to install your Operating System & Programming IDE (like android studio or any other) that will boost loading time of the IDE software, because as per my experience in running android studio on SSD drive is 10X times faster as compaired with HDD.


SSD Storage is very important & is been ignored by many people while buying new laptop for software development.

My Experience when i switched to SSD : When i used HDD with android studio installed, it took more then 10 minute to load it and even android Emulator used to load very slow almost 10-15 min but now a year back, i switched to SSD & boom now my system boot in just 1 min or less & android stdio loaded completely with build gradle file in just 2 minute or less.

For development with HTML & CSS i.e. web development 4 GB RAM is enought but when it comes to IDE such a android studio which need more RAM memory, 8 GB of RAM is Recommanded for Smooth run android in laptop

Note: if your laptop don’t have SSD then even increasing the RAM to 32 GB, is off no use: so better Buy a laptop that has SSD storage a primary memory.

3. Procesor i5:-


If you are android developer choice a laptop with i5 4th generation or higher, because in low processor like i3, the IDE will run properly but sometime you may face issue such as android studio handing/lagging, build time is more, long time for build to generate apk, Emulator not working or Emulator not responding etc,

I recommended for low budget people, go with atleast i5 4th generation or higher, Best choice is i5 7th generation & higher.

4. Graphic Card:-

graphic card

As such Graphics Card is not that recommended for android development, but if you are a game developer then the graphic is required so better buy a laptop that a graphic card in it.

Graphic card is not required but in graphical view of UI xml design in android studio will boost the view a give a developer a high graphic feeling.

Recommended : Graphic car ( 2gb or higher) (not mandatory)

5 Top best laptop for programming – Android development 2021

1. Apple MacBook Air with Apple M1 Chip

The Apple laptop are best for productivity and apple laptop has longer battery life i.e. 18 hours. The Appe Macbook Air with M1 chip for a giant leap in CPU,GPU and machine learning performance, has upto 8 core CPU that boost performance. Upto to 8 GPU cores gives 5x faster graphics. 16 core Neural Engine that help machine learning developer speed up the execution.

Apple MacBook Air with M1 chip
Operating SystemMacOS 10.14 Mojave
Display13.3-inch(diagonal) LED backlit wiescreen display
ProcessorApple M1 Chip,8-core CPU
Storage256 GB or 512 GB SSD
Apple Macbook Air Specification

Click here to learn more or buy Apple MacBook Air now

2. Lenovo Ideapad S145

Lenovo Ideapad s145
Operating SystemWindows 10
Display15.6 Inch
ProcessorIntel i5 10th generation
StorageHDD : 1 TB & SSD: 256GB
Lenovo IdeaPad Specification

Click here to learn more or buy Lenovo IdeaPad S145 now

3. HP Pavilion Gaming  15-ec1052AX

HP Pavilion
BrandHP Pavilion
Operating SystemWindows 10
Display15.6 Inch
ProcessorAMD Ryzen 5 4600H
StorageHDD : 1 TB & SSD: 256GB
Graphic CardNVIDIA GeForce GTX 1650, 4 GB
HP Pavilion Gaming Specification

Note: Always install Operating System & any of your Programming IDE(Eg: Android Studio) in SSD drive, so that the loading speed of OS and software will be 10x times faster.

Click here to learn more or buy HP Pavilion laptop now

4. Lenovo Legion 5

The Lenovo Legion 5 is very ultra-light and very slim and portable Gaming laptop, it’s a perfect gaming laptop for Game Lover, and best laptop for android development.

Lenovo legion 5
BrandLenovo, Legion 5
Operating SystemWindows 10
Display15.6 Inch, 1920 x 1080 (Full HD)
ProcessorAMD 4th generation Ryzen 5 4600H
StorageHDD : 1 TB & SSD: 256GB
Graphic CardNVIDIA GeForce GTX 1650, 4 GB
Lenovo Legion 5 Specification

Click here to learn more or buy Lenovo Legion 5 now

5. Acer Predator Helios 300 PH315-53-72E9

acer predator helios 300
BrandAcer, Predator Helios 300
Operating SystemWindows 10
Display15.6 Inch, 1920 x 1080 (Full HD)
ProcessorIntel i7 10th Generation
StorageHDD : 1 TB & SSD: 256GB
Graphic CardNVIDIA GeForce RTX 2060, 6 GB
Acer Predator Helios Specification

Click here to learn more or buy Acer Predator Helios 300 now

Recommended Post

Coding books for beginners