Home Blog Page 89

Flutter Photo View widget with zoomable image gallery

2
Flutter Photo View widget with zoomable image gallery
Flutter Photo View widget with zoomable image gallery

Hi Guys, welcome to proto coders point In this Flutter Tutorial will see above flutter photo view package library widget.

Flutter Photo View widget with zoomable image gallery

Photo View widget in flutter is a simple zoomable image or any content widget in flutter application development.

Using PhotoView widget on any widget view enable the widget images to become able to add zoom effect and a pan with user gestures such a rotate,pinch and drag gestures.

It also can show any widget instead of an image, such as Container, Text or a SVG.

This image viewer widget is super simple to use and play, Flutter zoom photo view widget is extremely customizable through the various options it provide and easy  controllers.

For more details visit official site HERE

Let’s begin implementing this flutter widget in our project

Step 1:  Create new Flutter project

Create a new Flutter Project in android-studio or any other Framework or open your existing flutter project

File > New > New Flutter project

Once your project is ready remove all the default dart code from main.dart file

and just copy paste the below code in main.dart

main.dart

import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue, //primary theme color
      ),
      home: MyHomePage(), //call to homepage class
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Photo View + Zoomable widget"),
      ),
      // your body code here
    );
  }
}

Step 2:  Add Dependencies

Then, you need to add dependencies in your project

open pubspec.yaml file and under dependencies line add below

dependencies:
  photo_view: ^0.9.1

Step 3: import the photo view widget package

Once you have added photo_view dependencies in your project now you can use those packages into your project by just importing photo_view.dart library

import 'package:photo_view/photo_view.dart';

on the top of main.dart file  add this import statement.

This allows you to make user of flutter zoomable image photoViewer library in main.dart file

Step 4: Create a folder(assets) and add path to asset folder in pubspec.yaml file

You need to create a assets folder and assign the path to be able to access images under assets folder.

Right click ( project ) > New > Directory

Name it as assets  and then add some images under that folder.

creating image directory in flutter app
creating image directory in flutter app

After you add images in assets folder open pubspec.yaml file to assign access path to assets folder for your project, So that your project can easily use that folder.

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
  - assets/
  # add the above assets exactly below users-material-----

Then, now the project is ready to make use of Flutter PhotoView zoomable image widget

Zoom image  flutter basic code base

import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue, //primary theme color
      ),
      home: MyHomePage(), //call to homepage class
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Photo View + Zoomable widget"),
      ),
      // add this body tag with container and photoview widget
      body: Container(
          child: PhotoView(
        imageProvider: AssetImage("assets/nightwolf.jpeg"),
      )),
    );
  }
}

The above code will result you with:

flutter image zoom gallery example

Photo View Gallery

If you want to show more that 1 image in a form of slidable image gallery then you need to user PhotoViewGallery.dart package

import 'package:photo_view/photo_view_gallery.dart';

Copy paste the below code to  in main.dart file

Flutter photoview gallery example

import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue, //primary theme color
      ),
      home: MyHomePage(), //call to homepage class
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final imageList = [
    'assets/nightwolf.jpeg',
    'assets/lakeview.jpeg',
    'assets/redsundet.jpeg',
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Photo View + Zoomable widget"),
      ),
      // add this body tag with container and photoview widget
      body: PhotoViewGallery.builder(
        itemCount: imageList.length,
        builder: (context, index) {
          return PhotoViewGalleryPageOptions(
            imageProvider: AssetImage(imageList[index]),
            minScale: PhotoViewComputedScale.contained * 0.8,
            maxScale: PhotoViewComputedScale.covered * 2,
          );
        },
        scrollPhysics: BouncingScrollPhysics(),
        backgroundDecoration: BoxDecoration(
          color: Theme.of(context).canvasColor,
        ),
        loadingChild: Center(
          child: CircularProgressIndicator(),
        ),
      ),
    );
  }
}

Result : 

flutter image gallery photo viewConclusion

In the Flutter Tutorial we learned how can we display an image or photo with customizable, rotatable image, and zoomable image in flutter using the PHOTO VIEW LIBRARY.

The Flutter PhotoView Gallery is one of the best way to show a zoomable image in flutter application.

 

Flutter Slidable ListView Actions on ListTiles

1
Flutter Slidable ListView Action on ListTiles
Flutter Slidable ListView Action on ListTiles

Hi Guys, Welcome to Proto Coders Point In this Flutter Tutorial we will implement Flutter Slidable action on ListView with ListTile widget.

Flutter Slidable Widget

A Flutter Slidable Widget can be applied on Flutter ListView with ListTile widget that can help developer to give left or right directional slide actions with we create a beautiful User Interface and User Experience where user this Slidable widget to dismiss any listTile he don’t want to user.

Eg: you might have used gmail mobile app which makes user of Slidable listTile where you can easily slide left or right on the email you recieved where you can take different actions like delete the mail, or mark it as important and many more actions

let’s begin implementing Flutter Slidable in our project

Adding this package in our project

To add this slidable package into our project you need to

Add this to your package’s pubspec.yaml file:

dependencies:
  flutter_slidable: ^0.5.4  // version might vary

Note : the verison might vary by time so just go to official site to get latest version of this library.

once you add the dependencies in pubspec.yaml file just click on Packages get, and then required package is been added into our flutter project.

Importing package

As you added the dependencies all the required packages will be added to your project.

All you need to do is just import the package dart file where every it’s requited.

import 'package:flutter_slidable/flutter_slidable.dart';

Snippet code of Flutter Slidable

Slidable(
  actionPane: SlidableDrawerActionPane(),
  actionExtentRatio: 0.25,
  child: Container(
    color: Colors.white,
    child: ListTile(
      leading: CircleAvatar(
        backgroundColor: Colors.indigoAccent,
        child: Text('$3'),
        foregroundColor: Colors.white,
      ),
      title: Text('Tile n°$3'),
      subtitle: Text('SlidableDrawerDelegate'),
    ),
  ),
  actions: <Widget>[
    IconSlideAction(
      caption: 'Archive',
      color: Colors.blue,
      icon: Icons.archive,
      onTap: () => _showSnackBar('Archive'),
    ),
    IconSlideAction(
      caption: 'Share',
      color: Colors.indigo,
      icon: Icons.share,
      onTap: () => _showSnackBar('Share'),
    ),
  ],
  secondaryActions: <Widget>[
    IconSlideAction(
      caption: 'More',
      color: Colors.black45,
      icon: Icons.more_horiz,
      onTap: () => _showSnackBar('More'),
    ),
    IconSlideAction(
      caption: 'Delete',
      color: Colors.red,
      icon: Icons.delete,
      onTap: () => _showSnackBar('Delete'),
    ),
  ],
);

Built-in slide actions

This package comes with 2 kinds of slide actions:

  • SlideAction, which is the most flexible. You can choose a background color, or any decoration, and it takes any widget as a child.
  • IconSlideAction, which requires an icon. It can have a background color and a caption below the icon.

In this Flutter Tutorial we are making use of IconSlideAction, so that we can easily add some icons with background color and some caption to it.

Built-in action panes

Action panes is required  to add the slidable listView ListTile

This package comes with 4 kinds of action panes:

  • SlidableBehindActionPane : The slide actions stay behind the item while it’s sliding
  • SlidableScrollActionPane : The slide actions follow the item while it’s sliding
  • SlidableDrawerActionPane : The slide actions animate like drawers while the item is sliding
  • SlidableStrechActionPane : The slide actions stretch while the item is sliding

Complete Code on Flutter Slidable with ListView.builder  with ListTile

In the Below Code i have created a list of Strings that range from 0 – 9 (i.e 10 list items)

final List<String> items =
        new List<String>.generate(10, (i) => "item  ${i + 1}");

Then, In the body part we have ListView Builder that simple returns Slidable widget.

This Sliable widget have  4 other properties those are:

actionPane : This is mandatory to be included there are 4 build-In actionPane ( check out able )

actionPane: SlidableDrawerActionPane()

action :  This is primary action that show when listView is slided from left side.

actions: <Widget>[
  IconSlideAction(
    icon: Icons.more,
    caption: 'MORE',
    color: Colors.blue,
  ),
],

secondaryAction : As the slidable property say it an secondary action that show when  listView is slided from right side.

Finally, the child : which can be any widget, in this flutter slidable tutorial i have added ListTile as a child.

Below is the Complete Code base just copy paste it in main.dart file

main.dart 

ListView builder ( without any divider color )

without listview seperator divider
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final List<String> items =
        new List<String>.generate(10, (i) => "item  ${i + 1}");
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter Slideable Example"),
      ),
      body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context, int index) {
            return Slidable(
              actions: <Widget>[
                IconSlideAction(
                  icon: Icons.more,
                  caption: 'MORE',
                  color: Colors.blue,
                  //not defined closeOnTap so list will get closed when clicked
                  onTap: () {
                          print("More ${items[index]} is Clicked");
                  }
                ),
              ],
              secondaryActions: <Widget>[
                IconSlideAction(
                  icon: Icons.clear,
                  color: Colors.red,
                  caption: 'Cancel',
                  closeOnTap: false, //list will not close on tap
                  onTap: () {
                      print("More ${items[index]} is Clicked");
                   }
                )
              ],
              child: ListTile(
                leading: Icon(Icons.message),
                title: Text("${items[index]}"),
                subtitle: Text("Slide left or right"),
                trailing: Icon(Icons.arrow_back),
              ),
              actionPane: SlidableDrawerActionPane(),
            );
          }),
    );
  }
}

ListView Seperated ( with Divider )

How to add a seperator or divider in flutter ListView ?

separatorBuilder: (context, index) => Divider(
              color: Colors.black,
            ),

Complete Code with ListView Seperated

listview seperated divider
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final List<String> items =
        new List<String>.generate(10, (i) => "item  ${i + 1}");
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter Slideable Example"),
      ),
      body: ListView.separated(
          separatorBuilder: (context, index) => Divider(
                color: Colors.black,
              ),
          itemCount: items.length,
          itemBuilder: (context, int index) {
            return Slidable(
              actions: <Widget>[
                IconSlideAction(
                  icon: Icons.more,
                  caption: 'MORE',
                  color: Colors.blue,
                  onTap: () {
                         print("More ${items[index]} is Clicked");
                  }
                ),
              ],
              secondaryActions: <Widget>[
                IconSlideAction(
                  icon: Icons.clear,
                  color: Colors.red,
                  caption: 'Cancel',
                  onTap: () {
                           print("Cancel ${items[index]} is Clicked");
                       }
                )
              ],
              child: ListTile(
                leading: Icon(Icons.message),
                title: Text("${items[index]}"),
                subtitle: Text("Slide left or right"),
                trailing: Icon(Icons.arrow_back),
              ),
              actionPane: SlidableDrawerActionPane(),
            );
          }),
    );
  }
}

Learn more about Flutter slidable widget on official site

Recommended Articles

listwheelscrollview3D ListView in flutter

Flutter Image Slider

Mobile Application Development in 2020

2
Mobile Application Development in 2020
Mobile Application Development in 2020

Hi Guys, welcome to Proto Coders Point. This article will be learning all about the Future of Mobile Application Development in 2020.

What is Mobile Application Development ?

Basically a Mobile Application Development is a process of designing a Beautiful UI Mobile app for mobile Devices, In the Process of developing a mobile application a developer will pre-install on his mobile as a part of testing process to test all the modules. During this process any mobile app developer must consider a different screen size , hardware specofication and he should also need to the app in different version of mobile OS.

Mobile Application Development has been steadily growing in couple of years and this mobile application industry is generating lot of revenues and also creating best software development job for graduate.

mobile app developer

Benefits of Mobile App Development?

In modern days mobile technology has been boosted, now a days mobile application is blended with all the business operation and also build opportunity to boost sales in market.

Mobile Technology is been used to send notification to their customer about the new products that is be launched, we can also use online coupons for discounts offers.

smartphone user

Now a days SmartPhones are been used all most every where in this earth and mobile usage is been increasing day by day.

Platform for mobile Applocation Development in 2020

  • Front-end development tools
  • Back-end servers
  • Security add-on layers
  • System Software
  • Mobile app testing

Front-end development tools

In Front End Developement all the focus will be on creating a best user interface and also user experience (UI-UX Designing), that makes users of the application attracted to the app.

Front-end development

Back-end Servers

The Back-End is a place where all the server side code get executed, that receives a request from a client(user) for some data, then the server sends back the requested data to the client(user), In back-end it also include the database where all the data will be stored.

back end servers

Security add-on layers

In every field their must be a security layers where users data will be hidden from out-side world, this Create safety for the application user.

  • App wrapping for security
  • Data encryption
  • Client actions
  • Reporting and statistics

Mobile Testing

In mobile testing the developed app is been tested in different version of OS, and even the app is been tested using VPN to change the current location and check if data is been transmited properly to our targated location.

mobile app testing process

  • Google Android Emulator – The Developer makes use of Google Emulator which is basically runs on android OS.
  • Testing mobile Device –  The app developer can also test the application in his own testing mobile device.

Most Commonly used Tools in mobile Application Development

Here are some commonly used tools in market today in 2020

Android – Studio :

Before, In android application development we where making use of java as programming language but now Google came with it’s own android development language called Kotlin.

In android Development we make use of IDE (Integrated Development Envirnoment) tools called Android-Studio.

Download link is here

android studio IDE

Android uses Dalvik ( discontinued process virtual Machine ) to execute application written for android OS. Therefore android application can only run on android devices.

The best thing for developer is that android-studio is completly free to use and develop best android application.

Unity Game Engine

Unity is a cross- platform application development mostly know as game engine which is developed by Unity Technology.

It was first released in JUNE 2005 at Apple Inc.

The Unity editor is supported on all the OS such as windows and maxOS.

This Unity Engine is more powerful for building games for more then 25 different platforms including mobile, desktop, consoles, and virtual reality.

Programming language used in unity game development are C#, JavaScript, Boo, other .NET-based languages

Unity Game Engine

This tools free for beginners for low level Game application development but to development high end games you need to buy commercial development licenses.

Flutter Application Development

The Flutter is a cross platform development framework introduced by Google, Flutter Application is done using Dart programming language – dart language is very simple language for any developer who knows basic of java development.

Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.

flutter text icon

To develop an app using Flutter you need make use of an IDE ( either android-studio, xCode , IntelliJ IDEA )

here is a artitcle on how to install flutter in android-studio ?

List Of Top Best Mobile App Development Companies India

mobile app development companies

  1. Konstant Infosolutions
  2. Openxcell
  3. Hidden Brains InfoTech
  4. MacAppStudio
  5. SourceBits
  6. IndiaNIC InfoTech
  7. Appinventiv

Navigation Side Drawer in Flutter with Example

0
Flutter Navigation Drawer With Example
Flutter Navigation Drawer With Example

Hi Guys Welcome to Proto Coders Point, In this Flutter Tutorial we gonna Talk about Flutter Navigation Drawer which is basically a Flutter Slide Menu.

In Flutter Application Development Navigation Drawer are basically used with the Scaffold.drawer Property, where Scaffold must have an appBar to show Drawer opening icon, The Drawer child usually is a ListView which first child is a DrawerHeader that are normally used to show current logIn user data.

The Remaining Drawer children are often been filled using ListTiles.

let’s Start implementing Flutter Navigation drawer Slide menu into our project

Flutter Navigation Drawer with Example

Step 1 : Create a new Flutter Project

offCourse you need to create a new Flutter project or open you existing Flutter project all left to your choice

File > New  > New Flutter Project

Fill all the required details to create  a new project.

Step 2 : Create 3 new Dart files in your flutter project

To create new dart file under your project,

Your_project > lib > (right click) New > Dart File

Then in lib directory you need to create 3 Dart Files and name it as ProfilePage.dart , Setting Page.dart , DrawerCode.dart.

Step 3 : Add a Scaffold Widget with appBar widget and drawer widget in main.dart

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Navigation Drawer"),
      ),
      drawer: DrawerCode(),
    );
  }
}

add a Scaffold widget with a appBar and drawer property in it.

Here DrawerCode is an class that has drawer widget in it.

The complete code of main.dart file is below just copy paste it in main page.

main.dart

import 'package:flutter/material.dart';
import 'DrawerCode.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Navigation Drawer"),
      ),
      drawer: DrawerCode(), // this is drawerCode page
    );
  }
}

Step 4 : Adding Required widget in Navigation Drawer Code

Snippet Code

Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          DrawerHeader(
            decoration: BoxDecoration(color: Colors.blue),
            child: Text("Drawer"),
          ),
        ],
      ),

The above Snippet code is for explaination about Flutter Drawer

In Flutter Drawer their must be a child widget i.e ListView.

Then this listView that can have any numbers of children : <Widget>, Here in above snippet code i gave Flutter DrawerHeader widget that will aquire some space in the top of Drawer with some decoration to it, the DrawerHeader in turn has a child which are be any widget here  have just for simple added a Text Widget.

Then the Second widget will be  a ListTiles here is the Snippet code for that.

ListTile(
           leading: Icon(Icons.person_outline),
           title: Text("Profile"),
           onTap: () {
             Navigator.pop(context);
             Navigator.push(
                 context, MaterialPageRoute(builder: (context) => Profile()));
           },
         ),

ListTile widget has a leading property with Icon as an Widget you can set a icon to the flutter Drawer, title property as a Text , and an onTap method property that will handle all the  task when user clicks on the ListTile.

The Complete Code is below just create a DrawerCode.dart file and copy paste the below lines of Flutter Drawer Code.

DrawerCode.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_drawer/ProfilePage.dart';
import 'package:flutter_drawer/SettingPage.dart';

class DrawerCode extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          DrawerHeader(
            decoration: BoxDecoration(color: Colors.blue),
            child: Column(
              children: <Widget>[
                Flexible(
                  child: Container(
                    width: 100,
                    height: 100,
                    margin: EdgeInsets.only(bottom: 5),
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      image: DecorationImage(
                          image: NetworkImage(
                              'https://secure.gravatar.com/avatar/3a719607819fc579c2aafd4d21dad3d1?s=96&d=mm&r=g'),
                          fit: BoxFit.fill),
                    ),
                  ),
                ),
                Text(
                  "Rajat Palankar",
                  style: TextStyle(
                      fontSize: 15.0,
                      fontWeight: FontWeight.w500,
                      color: Colors.white),
                ),
                Text(
                  "https://protocoderspoint.com/",
                  style: TextStyle(
                      fontSize: 12.0,
                      fontWeight: FontWeight.w500,
                      color: Colors.white70),
                ),
              ],
            ),
          ),
          ListTile(
            leading: Icon(Icons.person_outline),
            title: Text("Profile"),
            onTap: () {
              Navigator.pop(context);
              Navigator.push(
                  context, MaterialPageRoute(builder: (context) => Profile()));
            },
          ),
          ListTile(
            leading: Icon(Icons.settings_applications),
            title: Text("Setting"),
            onTap: () {
              Navigator.pop(context);
              Navigator.push(
                  context, MaterialPageRoute(builder: (context) => Setting()));
              print("Go to Settings");
            },
          ),
          ListTile(
            leading: Icon(Icons.arrow_back),
            title: Text("Logout"),
            onTap: () {
              print("Logout Users");
              Navigator.pop(context);
              SystemNavigator.pop();
            },
          ),
        ],
      ),
    );
  }
}

Step 5 : adding codes for Navigated Drawer pages

Both the below pages will simply show a Text Widget indicating which page is been open.

ProfilePage.dart

When user Tap on menus listTitles from Navigation drawer the user will navigate to the selected option.

import 'package:flutter/material.dart';
import 'package:flutter_drawer/DrawerCode.dart';

class Profile extends StatefulWidget {
  @override
  _ProfileState createState() => _ProfileState();
}

class _ProfileState extends State<Profile> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Navigator Drawer"),
      ),
      drawer: DrawerCode(),
      body: Center(
        child: Text("Profile Page"),  // this is profile page
      ),
    );
  }
}

SettingPage.dart

import 'package:flutter/material.dart';

import 'DrawerCode.dart';

class Setting extends StatefulWidget {
  @override
  _SettingState createState() => _SettingState();
}

class _SettingState extends State<Setting> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Navigator Drawer"),
      ),
      drawer: DrawerCode(),
      body: Center(
        child: Text("Setting Page"), // Then here is setting page
      ),
    );
  }
}

All set, Now your Flutter Project with Navigation Drawer is ready to test and use.

 

Firebase UI RecyclerView Adapter Android Tutorial with Example

6
Firebase UI RecyclerView Adapte

Hi Guys, Welcome to Proto Coders Point, In this Android tutorial we will implement Firebase UI RecyclerView Adopter

This Project will basically fetch / retrive data from firebase using Firebase UI recyclerview adapter library and display it’s contents in recyclerview as a GridView.

check out :  RecyclerView With GridLayoutManager Show Grid View in androidx this post will help you in understanding basic about RecycleView in android and how to show data in RecyclerView with GridLayoutManager.

Let’s Start Implementation the project.

Demo on How this Project will look at End of this tutorial

Firebase UI RecyclerView Adapter Android Demo

Firebase Ui RecyclerView Adapter Android Tutorial with Example

FirebaseUI makes it simple to bind data from the Firebase Realtime Database to your app’s UI.

Step 1 : Create a new Android Project

OfCouse, your need to create a new android project using android-studio, or else you can make use of your existing android project.

Step 2 : Adding your project to Firebase Console

Check out below video on how to connect android app to firebase console from android studio.

Note: this video is related to Cloud Messaging FCM to send push Notification but the process is same so watch 0 to 2 min minutes of the video to add project to firebase console

or

Follow this steps :

tools -> firebase -> analytics -> log-on Analytics event 

you will see 2 button just click on then

  • Connect your project to firebase.
  • add Analytic dependencies to your project

and you are done your app is now connected to Firebase Console project.

Step 3 : Adding Required Firebase UI Dependencies in your project.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

    implementation 'com.firebaseui:firebase-ui-database:5.0.0' //add firebase ui recyclerview dependency
    implementation 'com.google.firebase:firebase-core:17.2.2' // adding firebase core dependency
    implementation 'com.google.android.material:material:1.2.0-alpha02'  //material design for RecycleView
    implementation 'com.squareup.picasso:picasso:2.71828'  // picasso library dependencies to show image in imageView
}

For this project we need total 4 dependencies

FirebaseUI – this is used to show data retrieved from firebase realtime database in recyclerView.

material – this has the design view for example: this library has recyclerView Widget in it.

picasso library : used to show image fetched from firebase realtime database to imageView.

check out : Picasso android library tutorial – Picasso image loader

Step 4 : Create a RealTime Database in firebase console

Follow this steps to create realtime database.

  1. open your firebase console,
  2. navigate to your project under firebase console
  3. on the left side you will see develop option under that open Database
  4. create a new RealTime Database

Here is how my data looks in Firebase console

Firebase RecycleView Adopter database structure
Firebase database structure

Firebase stored data in JSON format

Here is how the above data looks in json format

{
  "products" : {
    "accessories" : {
      "product1" : {
        "image" : "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRcJUkOrtmOwQFdLVHt--R-q-4SHO5CEFZcmR14LYNhyMLwOUTg",
        "link" : "https://www.amazon.inffff/",
        "name" : "Dumbbell Rack"
      },
      "product2" : {
        "image" : "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcT_PQP9-9MWy7lmZBaYMpDb2jyBh4KLyJOA37uSXgiXQZ-3th3e",
        "link" : "https://www.amazon.in/",
        "name" : "Rubic 2*2 Cube"
      },
      "product3" : {
        "image" : "https://support.apple.com/library/content/dam/edam/applecare/images/en_US/homepod/watch-product-lockup-callout.png",
        "link" : "https://www.amazon.in/",
        "name" : "Apple Watch"
      },
      "product4" : {
        "image" : "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQtZ5xPeZyLwIMnIXQgODfr20YSgTUP-6l3Xc-J2pOgUZyPwx3L",
        "link" : "https://www.amazon.in/",
        "name" : "DSLR Camera"
      },
      "product5" : {
        "image" : "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSYYCpkawEmDTQoCipEaP4BGBEHtgAjbJDS6G9CIigDu-EBsG2V",
        "link" : "https://www.amazon.in/",
        "name" : "Bluetooth Headphone"
      },
      "product6" : {
        "image" : "https://images.prismic.io/rpf-products/c4f1986d2ba2737359c10225d1dc1c8d59d3cfd7_compute-module-main-1-1793x1080.jpg?auto=compress,format",
        "link" : "https://www.amazon.in/",
        "name" : "RaspberryPI"
      },
      "product7" : {
        "image" : "https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4mQFV?ver=c77b&q=90&m=6&h=195&w=348&b=%23FFFFFFFF&l=f&o=t&aim=true",
        "link" : "https://www.amazon.in/",
        "name" : "Play Station"
      }
    }
  }
}

create your own database or just download my database file from https://drive.google.com/file/d/1EPJofN5OA6wQG_jy0tggFZU5PKmz91hC/view?usp=sharing

after downloading just import the file in realtime database

importing JSON file in firebase

Just open realtime database and click on 3 vertical line a popup dropdown list will open click on import JSON > select the file you have downloaded and next..

Hence my Firebase Database structure will get imported into you firebase project.

Then, Now all is been set on the server – side

Just go back to our android Studio.

step 5 : Create a new XML file and Name it as customlayout

customelayout.xml

This xml file 2 views that are ImageView and a text View.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:cardBackgroundColor="#E0D5D5"
        android:orientation="vertical"
        android:layout_margin="5dp">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <ImageView
                android:id="@+id/productimage"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:scaleType="fitXY"
                android:layout_gravity="center_horizontal"
                />
            <TextView
                android:id="@+id/text1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:background="#004DB4"
                android:textSize="15sp"
                android:textColor="#FFF"
                android:gravity="center"
                android:text="logo1"/>

        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>

Step 6 : Open activity_main.xml and Copy below Code

activity_main.xml

This XML file have only one View that is RecyclerView where we gonna show our data that is retrieve from firebase database using Firebase UI RecyclerViewAdapter.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:theme="@style/Theme.AppCompat.Light">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#056FF0"
        android:textSize="25sp"
        android:layout_gravity="center"
        android:textStyle="bold|italic"
        android:text="Products"/>


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recyclerViewGirdView"/>


</LinearLayout>

Step 7 : Create a Constructor class that holders all the data from firebase.

you need a class that handles data retrieved from firebase.

create a new java file and name it as product_getter_setter.java this file has a constructor and getter and setter methods that helps in getting and setiing the data.

product_getter_setter.java

package com.ui.recycleview.gridview.firebaserecyclerviewadapter;

public class product_getter_setter {

    String name,image,link;

    public product_getter_setter() {
    }

    public product_getter_setter(String name, String image, String link) {
        this.name = name;
        this.image = image;
        this.link = link;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }
}

Step 8 : Main_Activity.java with has FirebaseRecyclerAdapter method

Main_Activity.java

open Main_Activity.java and copy paste below lines of java code

package com.ui.recycleview.gridview.firebaserecyclerviewadapter;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;

public class MainActivity extends Activity {

    RecyclerView recyclerView;

    Query query1;
    private DatabaseReference mdatabasereference;
    private ProgressDialog progressDialog;
    FirebaseRecyclerAdapter<product_getter_setter, BlogViewHolder> firebaseRecyclerAdapter;
    LinearLayoutManager mLayoutManager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setMessage("Loading Products Please Wait...");
        progressDialog.show();

        mdatabasereference = FirebaseDatabase.getInstance().getReference("products").child("accessories");

        recyclerView = (RecyclerView) findViewById(R.id.recyclerViewGirdView);


    }

    @Override
    protected void onStart() {
        super.onStart();
        query1 = FirebaseDatabase.getInstance().getReference().child("products").child("accessories");
        FirebaseRecyclerOptions<product_getter_setter> options =
                new FirebaseRecyclerOptions.Builder<product_getter_setter>()
                        .setQuery(query1, product_getter_setter.class)
                        .build();

        Log.d("Options"," data : "+options);



        firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<product_getter_setter, BlogViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull BlogViewHolder blogViewHolder, final int i, @NonNull product_getter_setter product_get_set_v) {

                blogViewHolder.setname(product_get_set_v.getName());
                String image_url =blogViewHolder.setimage(product_get_set_v.getImage());
                String link= product_get_set_v.getLink();
                Log.d("LINKDATA"," data : "+link);

                blogViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        final String productid=getRef(i).getKey();
                        Log.d("productid"," data : "+productid);


                        mdatabasereference.child(productid).addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                String finallink = dataSnapshot.child("link").getValue(String.class);
                                Log.d("productLink"," data : "+finallink);

                                if(finallink!=null)
                                {
                                    Uri uriUrl = Uri.parse(finallink);
                                    Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
                                    startActivity(launchBrowser);
                                }

                            }

                            @Override
                            public void onCancelled(@NonNull DatabaseError databaseError) {

                            }
                        });

                    }
                });

            }

            @NonNull
            @Override
            public BlogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.custom_layout, parent, false);
                progressDialog.dismiss();
                return new BlogViewHolder(view);
            }
        };
        firebaseRecyclerAdapter.startListening();
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),2);
        recyclerView.setLayoutManager(gridLayoutManager);

        recyclerView.setAdapter(firebaseRecyclerAdapter);
    }

    public static class BlogViewHolder extends RecyclerView.ViewHolder
    {
        View mView;

        public BlogViewHolder(View itemView)
        {
            super(itemView);
            mView=itemView;



        }
        public void setname(String name)
        {
            TextView ename=(TextView)mView.findViewById(R.id.text1);
            ename.setText(name);

        }

        public String setimage(String url)
        {
            ImageView image = (ImageView)mView.findViewById(R.id.productimage);
            Picasso.get().load(url).into(image);
            return url;
        }
    }
}

Step 9 : Adding Internet Permisson for your project

Then, as you know that we are fetching data from external source i,e our Firebase server, We definitely  need  access to internet permission to be set for our android project

open AndroidManifest.xml file  and app internet permission tag before <application> tag

<uses-permission android:name="android.permission.INTERNET"/>

All set now the app is ready to run for testing…..

Download Complete Firebase RecyclerView Adopter project from here:

https://drive.google.com/file/d/1qQRgVGN6nYpFwSh2UrZc74TjRIJOaYv5/view?usp=sharing

RecyclerView With GridLayoutManager Show Grid View in androidx

2

Hi Guys, welcome to Proto Coders Point,In this Android Tutorial we will implement RecyclerView with GridView basically using GridLayoutManager.

The RecyclerView is one of the advance and most flexiable version of ListView and GridView.

It is mostly used to show large number of data sets to the user when user scrolls the view.

it’s is available to use in Material Design of API leven 21 (i.e Android 5.0 Lollipop).

Demo of Final Result of this Tutorial

recycler View with Grid View layout manager

Gradle Dependency to use RecyclerView:

dependencies {
 ...
 implementation "com.android.support:recyclerview-v7:23.23.4.0"
 }

or

if you have latest version of android studio with androidx

you need to add material dependencies

dependencies
{
..............
implementation 'com.google.android.material:material:1.2.0-alpha04' // recycleView is inbuilt in this
}

The material package comes with RecycleView Components.

RecycleView XML code in older version of android studio

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="protocoderspoint.com.recyclerviewexample.MainActivity">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

RecycleView XML code for androidx

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycleview"/>
    
</LinearLayout>

RecyclerView With GridLayoutManager in androidx with Example

Let’s us now start implementing our android application with RecycleView with GridLayoutManager with example.

Step 1: Create a New Project And Name It RecyclerViewExample.

OfCouse, your need to create a new android project using android-studio, or else you can make use of your existing android project.

Step 2 : Add Required Dependencies

Once your project is ready you need to first add the recyclerView Dependencies in to your android project so that you can make user of recyclerView widget.

if you are using android-studio version that comes with migrating to androidx then better use material or else you can use recyclerView Dependencies.

The dependencies is been listed above.

Step 3 : Adding recyclerView in activity_main.xml

open > project > app > res > layout > activity_main.xml

And Copy and paste the below lines of xml code with recyclerView widget.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycleview"/>

</LinearLayout>

 

Step 4 : Create a new XML File and name it as row_layout_view.xml

This XML View will be Displayed under RecyclerView in activity_main.xml in a form of GridView

Here we  Simple have an imageView and a textView that will show some date sets.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical"
    android:layout_margin="5dp"
    android:background="@drawable/recyclebackground"
    >
    <!--
    grid items for RecyclerView GridView Example
    -->
    <ImageView
        android:id="@+id/image"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:scaleType="fitXY"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="....."
        android:gravity="center"
        android:background="#1E88E5"
        android:layout_gravity="center"
        android:textColor="#FAF5F5"
        android:textSize="15sp" />
</LinearLayout>

Step 5 : create a new xml file in drawable

Create a new drawable XML file in Drawable folder and name it recyclebackground.xml 

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!--
       stroke with color and width for creating outer line
    -->
    <stroke
        android:width="1dp"
        android:color="#000" />
</shape>

 

Step 6: Create a new Adopter Class

Then, you will need a Adopter class that will help you in  handling all the data and display then in recyclerView.

Create a new Adopter Class and name it as CustomRecycleAdopter.java

App > java > your Package (Right click) > New > java class

This CustomRecycleAdopter class will extends RecyclerView.Adapter class which incluse Viewholder in it.

Then  we will implement some override methods and create a constructor to get the data from Main_Activity Class.

In CustomRecycleAdapter class we have 2 methods those are OnCreateViewHolder that helps use to inflate the row_layout_view.xml view Items and then pass it to ViewHolder and the other method is onBindViewHolder that is been used to set the data in the views by the help of ViewHolder.

Then Finally we implement the setOnClickListener on the itemview that show use which gridView in recyclerView was clicked by the user

Then you Just Copy paste the Below Code

package com.ui.recycleview.gridview.layoutmanager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
public class CustomRecyclerViewAdopter extends RecyclerView.Adapter {
    ArrayList personNames;
    ArrayList personImages;
    Context context;
    public CustomRecyclerViewAdopter(Context context, ArrayList personNames, ArrayList personImages) {
        this.context = context;
        this.personNames = personNames;
        this.personImages = personImages;
    }
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // infalte the item Layout
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout_view, parent, false);
        // set the view's size, margins, paddings and layout parameters
        MyViewHolder vh = new MyViewHolder(v); // pass the view to View Holder
        return vh;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        // set the data in items
        MyViewHolder viewHolder= (MyViewHolder)holder;
        ((MyViewHolder) holder).name.setText( personNames.get(position).toString());
        ((MyViewHolder) holder).image.setImageResource((Integer) personImages.get(position));
        // implement setOnClickListener event on item view.
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(context,"Person : "+(position+1),Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    public int getItemCount() {
        return personNames.size();
    }
    public class MyViewHolder extends RecyclerView.ViewHolder {
        // init the item view's
        TextView name;
        ImageView image;
        public MyViewHolder(View itemView) {
            super(itemView);
            // get the reference of item view's
            name = (TextView) itemView.findViewById(R.id.name);
            image = (ImageView) itemView.findViewById(R.id.image);
        }
    }
}

Step 7 : Passing Data from Main_Activity.java to CustomRecyclerAdopter.java

Now, Firstly you need to get References to recycleView and then pass data to Adopter.

Then we are creating a list of data using java ArrayList name it as Person Name and likewise i have created a list of Images using ArrayList.

There after we set the recyclerView with GridLayoutManager and then we set the Adopter that show the Grid Items in out RecyclerView Widget.

Main_Activity.java

package com.ui.recycleview.gridview.layoutmanager;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Arrays;
public class MainActivity extends AppCompatActivity {
    // ArrayList for person names
    ArrayList personNames = new ArrayList<>(Arrays.asList("Person 1", "Person 2", "Person 3", "Person 4", "Person 5", "Person 6", "Person 7","Person 8", "Person 9", "Person 10", "Person 11", "Person 12", "Person 13", "Person 14"));
    ArrayList personImages = new ArrayList<>(Arrays.asList(R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp,R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp, R.drawable.ic_person_black_24dp));
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        // get the reference of RecyclerView
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycleview);

        // set a GridLayoutManager with default vertical orientation and 2 number of columns
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(),2); // you can change grid columns to 3 or more

        recyclerView.setLayoutManager(gridLayoutManager); // set LayoutManager to RecyclerView
        //  call the constructor of CustomAdapter to send the reference and data to Adapter
        CustomRecyclerViewAdopter customAdapter = new CustomRecyclerViewAdopter(MainActivity.this, personNames,personImages);
        recyclerView.setAdapter(customAdapter); // set the Adapter to RecyclerView
    }
}

 

And the last thing is that you need to add some images in drawable to show them into Recycle GridView

I have simple created a vector images assets under drawable folder.

Just Right Click on Drawable  folder > New > Vector Assets

person_blue.xml

<vector android:height="24dp" android:tint="#0324FA"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FF000000" android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/>
</vector>