Learning's post

post
what is a SplashScreen?

A splash screen is a screen that appears when you open an app on your mobile device. So, we can say that it is the first impression for the user. It is commonly used to show an application logo or an image associated with an application.



















Implementation

So instead of using a layout file, we'll refer to the splash screen as the background of the activity theme. first, create an XML drawable splash_background.xml inside res/drawable folder in

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/white" />
    
    <item
        android:drawable="@drawable/ic_icon_vector"
        android:gravity="center" />

</layer-list>
 next step, set splash_groundground.xml as the background for your splash activity in the theme. Add a new splash to your splash activity.


<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_background</item>
</style>
Add your theme to AndroidManifest.xml as your splash activity theme.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.exmple.splash">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme">
        
        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Create a blank activity for SplashActivity.java without XML. This class will only redirect to MainActivity.java.

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        startActivity(new Intent(SplashActivity.this, MainActivity.class));
        finish();
    }
}



November 02, 20201 minuteauthorVivek Beladiya
post
We are recently developed a site into the gatsby. basically contact us feature is common in all website.
and we are implementing Mailchimp because it's a very popular platform in email market.

So, I will show you how to setup a Mailchimp in the Gatsby site.

## Using gatsby-source-mailchimp

Use your Mailchimp API key to download your campaigns into Gatsby’s GraphQL data layer!

Install the package by running the following command: `npm i gatsby-source-mailchimp --save`

### How to configure
Once the installation is complete, you can now add this plugin to your gatsby-config.js, like so:

Configure mailchimp Key and add this {resolve: `gatsby-source-mailchimp`} into the plugins array. code looks like

```
module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-mailchimp',
      options: {
        // Avoid including your key directly in your file.
        // Instead, opt for adding them to .env files for extra
        // security ;)
        key: 'asd712jdas90122jdas90122jkadsd1-usXX',
        rootURL: 'https://usXX.api.mailchimp.com/3.0',
      },
    },
  ],
  // ...
}
```

Above is the minimal configuration required to have it work. By default,
This plugin was made out of a specific necessity, so it doesn't cover all of Mailchimp’s data sources, focusing only on campaigns.

this plugin are provide few options. you can refer here.

## Using `.env` variables to hide your key
If you don’t want to attach your API key to the repo, you can easily store it in .env files by doing the following:

```
// In your .env file
MAILCHIMP_KEY = 'asd712jdas90122jdas90122jkadsd1-usXX';
```

```
// In your gatsby-config.js file
require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-mailchimp',
      options: {
        key: process.env.MAILCHIMP_KEY,
        rootURL: 'https://usXX.api.mailchimp.com/3.0',
        // ...
      },
    },
  ],
  // ...
};
```


October 31, 20201 minuteauthorShailesh Ladumor
post
Cardview is a widget provided by Android to create a new look and functional UI. You can build your app with the following examples to make it look more professional. Cardview is a wonderful concept that makes your user experience better than the Android UI. Cardview is an Android Lollipop released with Android 5.0.















Customized CardView


First, add a CardView dependency to the application-level build.gradle file.

dependencies {
    implementation ‘androidx.cardview:cardview:1.0.0’
}
Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.
res > drawable > New > Drawable Resource File.





background1.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#FFAB00"
        android:endColor="#FFAB00">
    </gradient>
</shape>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#0091EA"
        android:endColor="#00BFA5">
    </gradient>
</shape>

Screenshot 2020-12-19 at 10.52.33 PM.png 4.64 KB
background3.xml








<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:startColor="#AEEA00"
        android:endColor="#FFD600">
    </gradient>
</shape>
Screenshot 2020-12-19 at 10.52.25 PM.png 4.75 KB
Now create a card view in the main XML file. Here I used  LinearLayout as the root widget, after using the card view. Below the codes that give you an idea of how to customize the card.
You can change it according to your needs.

activity_main.xml

<?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"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="173dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="20dp"
        app:cardCornerRadius="8dp">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg1"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Assam"
                        android:textColor="#000000"
                        android:textSize="22sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Current Location"
                        android:textColor="#000000"
                        android:textSize="14sp" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="25"
                    android:textColor="#000000"
                    android:textSize="28sp" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="6dp"
                        android:text="o"
                        android:textColor="#000000"
                        android:textSize="13sp" />

                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="18 %"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_marginStart="6dp"
                        android:text="11.25 AM"
                        android:textColor="#000000"
                        android:textSize="14sp" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="173dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="20dp"
        app:cardCornerRadius="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg2"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Delhi"
                        android:textColor="@color/white"
                        android:textSize="22sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="2 days ago"
                        android:textColor="@color/white"
                        android:textSize="14sp" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="39"
                    android:textColor="@color/white"
                    android:textSize="28sp" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="6dp"
                        android:text="o"
                        android:textColor="@color/white"
                        android:textSize="13sp" />

                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="35 %"
                    android:textColor="@color/white"
                    android:textSize="14sp" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_marginStart="6dp"
                        android:text="01.05 PM"
                        android:textColor="#D6D6D6"
                        android:textSize="14sp" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="173dp"
        android:layout_marginStart="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginEnd="20dp"
        app:cardCornerRadius="8dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bg3"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Darjeeling"
                        android:textColor="#000000"
                        android:textSize="22sp" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="2 weeks ago"
                        android:textColor="#000000"
                        android:textSize="14sp" />
                </LinearLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginStart="30dp"
                android:layout_marginTop="20dp"
                android:layout_marginEnd="30dp"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="12"
                    android:textColor="#000000"
                    android:textSize="28sp" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="6dp"
                        android:text="o"
                        android:textColor="#000000"
                        android:textSize="13sp" />

                </LinearLayout>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="9 %"
                    android:textColor="#000000"
                    android:textSize="14sp" />

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_marginStart="6dp"
                        android:text="05.00 AM"
                        android:textColor="#000000"
                        android:textSize="14sp" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </androidx.cardview.widget.CardView>
</LinearLayout>
Output :-

October 25, 20201 minuteauthorVivek Beladiya
post
Today I’m going to write on Create Floating Widget never stop closing the app from the background. First of all, you must know what is the service in Android.

What is a service in Android?

A service is a component that runs in the background without direct interaction with the user. Since the service has no user interface, it is not bound to the life cycle of the activity. If you want to repeat a task, using the service is the best way.
Service stops are one of the biggest problems when you clear the application from background functions.


My service is below:

public class FloatingViewService extends Service  {

    private WindowManager mWindowManager;
    private View mFloatingView;
    private View floatingButton;
    private final static float CLICK_DRAG_TOLERANCE = 10;

    private float downRawX, downRawY;
    private float dX, dY;
    int LAYOUT_FLAG;
    private SpeechRecognizer speechRecognizer;

    public FloatingViewService() {
    }
		Context context;

    public FloatingViewService(Context applicationContext) {
        super();
        context = applicationContext;
        Log.i("HERE", "here service created!");
    }
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
					 KeyguardManager myKM = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
              if( myKM.inKeyguardRestrictedInputMode()) {
                  Intent i = new Intent(this,FloatingViewService.class);
                  startService(i);
//            //it is locked
                } else {
                    Intent i = new Intent(this, FloatingViewService.class);
                    startService(i);
        //it is not locked
             }
            return START_STICKY;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_layout, null);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
        }

        final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                LAYOUT_FLAG,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mWindowManager.addView(mFloatingView, params);

        floatingButton.setOnTouchListener(new View.OnTouchListener() {
            private int initialX;
            private int initialY;
            private float initialTouchX;
            private float initialTouchY;

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        initialX = params.x;
                        initialY = params.y;
                        initialTouchX = event.getRawX();
                        initialTouchY = event.getRawY();

                        downRawX = event.getRawX();
                        downRawY = event.getRawY();
                        dX = v.getX() - downRawX;
                        dY = v.getY() - downRawY;

                        return true;

                    case MotionEvent.ACTION_UP:

                        float upRawX = event.getRawX();
                        float upRawY = event.getRawY();

                        float upDX = upRawX - downRawX;
                        float upDY = upRawY - downRawY;
                        return true;

                    case MotionEvent.ACTION_MOVE:
                        params.x = initialX + (int) (event.getRawX() - initialTouchX);
                        params.y = initialY + (int) (event.getRawY() - initialTouchY);
                        mWindowManager.updateViewLayout(mFloatingView, params);
                        return true;
                }
                return false;
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
AndroidManifest.xml  file and update your service declarations under the application tag. Also, add  FOREGROUND_SERVICE, INTERNET and  WAKE_LOCK .Make sure you don't forget to include them as they won't work otherwise.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          package="com.example.endless">

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

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">

        <service
                android:name=".FloatingViewService"
                android:enabled="true"
                android:exported="false">
        </service>

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

You can use the following code to check if the service is running. If the service is already in running mode, it does not need to be restarted otherwise start in your MainActivity.

FloatingViewService mFloatingService = new FloatingViewService(getApplicationContext());
  Intent mServiceIntent = new Intent(getApplicationContext(), mFloatingService.getClass());
if (!isMyServiceRunning(mFloatingService.getClass())) {
    startService(mServiceIntent);
}

Method isMyServiceRunning() is below add this in your MainActivity.

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            Log.i ("isMyServiceRunning?", true+"");
            return true;
        }
    }
    Log.i ("isMyServiceRunning?", false+"");
    return false;
}
Then Create a Floating Widget design. Create File floating_layout.xml Like This

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RelativeLayout
        android:id="@+id/rl_close_button"
        android:layout_width="100dp"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:id="@+id/relativeLayoutParent"
            android:layout_width="80dp"
            android:layout_height="70dp">

            <RelativeLayout
                android:layout_width="70dp"
                android:layout_height="70dp"
                android:background="@drawable/floating_round_main_shape">

                <RelativeLayout
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:layout_centerInParent="true"
                    android:background="@drawable/floating_inner_round_shape">

                    <ImageView
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:layout_centerInParent="true"
                        android:src="@drawable/ic_voice_icon" />

                </RelativeLayout>

            </RelativeLayout>

        </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

I hope it will help these services. 
Note:-This service will run better in Oreo and above versions.


October 04, 20203 minutesauthorVivek Beladiya
post
We are adding a sitemap in our all site pages for making sure search engines (such as Google) can find and crawl them all. 

So, I will show you how to set a sitemap on the Gatsby site.

To generate an XML sitemap, you will use the gatsby-plugin-sitemap package.

Install the package by running the following command: npm install gatsby-plugin-sitemap


How to configure

Once the installation is complete, you can now add this plugin to your gatsby-config.js, like so:

Configure siteUrl and add this {resolve: `gatsby-plugin-sitemap`} into the plugins array. code looks like


module.exports = {
  siteMetadata: {
    title: `InfyOm Technologies`,
    description: `InfyOm Technologies`,
    keyword: `InfyOm Technologies`,
    author: `@gatsbyjs`,
    siteUrl: `http://infyom.com`
  },
  flags: {
    PRESERVE_WEBPACK_CACHE: true,
  },
  plugins: [
    {resolve: `gatsby-plugin-sitemap`},
  ],}

Above is the minimal configuration required to have it work. By default, the generated sitemap will include all of your site’s pages.
you can exclude a path using the exclude option. you need to configure it

  • output (string) The file path and name. Defaults to /sitemap.xml.
  • exclude (array of strings) An array of paths to exclude from the sitemap.
code looks like,

module.exports = {
  siteMetadata: {
    title: `InfyOm Technologies`,
    description: `InfyOm Technologies`,
    keyword: `InfyOm Technologies`,
    author: `@gatsbyjs`,
    siteUrl: `http://infyom.com`
  },
  flags: {
    PRESERVE_WEBPACK_CACHE: true,
  },
  plugins: [
    {
	resolve: `gatsby-plugin-sitemap`,
    options: {
      output: `/some-other-sitemap.xml`,
        exclude: [`/category/*`, `/path/to/page`],
		}
	},
  ],
}
NOTE: This plugin only generates an output when run in production mode! To test your sitemap, run: gatsby build && gatsby serve

now we are done and open sitemap using your domain. for ex. https://xxx.com/sitemap.xml










September 28, 20201 minuteauthorShailesh Ladumor
post
What is a recycler view?

  • RecyclerView is used to show the data in the form of a scrollable list. It is a ViewGroup to display a large set of data. For each item in a large dataset, it displays a View. So RecyclerView is very useful no use the scrollable list.

Why use RecyclerView in Android?

  • One reason is so we can create a List through the LinearLayout and the orientation can be vertical. For example, in the Facebook application, all parameters will be the same as share, comment, like, etc. Now if we will take LinearLayout, all the views will create separate views in the memory.
Add dependencies :



dependencies {  

    implementation "androidx.recyclerview:recyclerview:1.1.0"
} 

Notes:

  • Androidx in recycler view dependencies:  implementation "androidx.recyclerview:recyclerview:1.1.0"
  • Your android studio, not androidx:  implementation 'com.android.support:recyclerview-v7:28.0.0'

Now we will add the RecyclerView layout in our activity_main.xml file

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout 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:id="@+id/recyclerView"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" />  
  
</RelativeLayout>

We create a layout file named row_layout.xml.

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout 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:id="@+id/recyclerView"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" />  
  
</RelativeLayout>

We create a layout file named row_layout.xml

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:orientation="horizontal">  
  
    <ImageView  
        android:id="@+id/image"  
        android:layout_width="300px"  
        android:layout_height="300px"  
        android:layout_marginLeft="10dp"  
        android:layout_marginTop="10dp"  
        android:src="@color/colorPrimaryDark" />  
  
    <TextView  
        android:id="@+id/description"  
        android:layout_width="250dp"  
        android:layout_height="55dp"  
        android:layout_toRightOf="@id/image"  
        android:layout_marginLeft="15dp"  
        android:layout_marginTop="35dp"  
        android:text="abcd"  
        android:textColor="#000"  
        android:textSize="30sp" />  
  
</RelativeLayout>

Create a Model Class :

public class Data {  
  
    public String name;  
  
    public String getName() {  
        return name;  
    }  
  
    public void setName(String name) {  
        this.name = name;  
    }  
  
    public int getImageId() {  
        return imageId;  
    }  
  
    public void setImageId(int imageId) {  
        this.imageId = imageId;  
    }  
  
    public int imageId;  
  
    Data(String name, int imageId) {  
        this.name = name;  
        this.imageId = imageId;  
    }  
} 

Create RecyclerVIew_Adapter.java

public class RecyclerView_Adapter extends RecyclerView.Adapter<View_Holder> {  
  
    List<Data> list = Collections.emptyList();  
    Context context;  
  
    public RecyclerView_Adapter(List<Data> data, Application application) {  
        this.list = data;  
        this.context = application;  
    }  
  
    @NonNull  
    @Override  
    public View_Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {  
        //Inflate the layout, initialize the View Holder  
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_layout, parent, false);  
        View_Holder holder = new View_Holder(v);  
        return holder;  
    }  
  
    @Override  
    public void onBindViewHolder(@NonNull View_Holder holder, int position) {  
  
        //Use the provided View Holder on the onCreateViewHolder method to populate the current row on the RecyclerView  
        holder.name.setText(list.get(position).name);  
        holder.imageView.setImageResource(list.get(position).imageId);  
  
    }  
  
    @Override  
    public int getItemCount() {  
        return list.size();  
    }  
} 

  • onCreateViewHolder()- It inflates the row layout and initializes the view holder. It handles findViewById) (methods, find views once, and recycle them so that repetitive calls are avoided.
  • onBindViewHolder()- It uses the onCreateViewHolder() View Holder to fill in the current RecyclerView row with data.
  • getItemCount()- This method returns the collection size which contains the items that we wish to show.
The code file of the ViewHolder Java class is listed below.

import android.view.View;  
import android.widget.ImageView;  
import android.widget.TextView;  
import androidx.recyclerview.widget.RecyclerView;  
  
public class View_Holder extends RecyclerView.ViewHolder {  
  
    TextView name;  
    ImageView imageView;  
  
    View_Holder(View itemView) {  
        super(itemView);  
        name = (TextView) itemView.findViewById(R.id.name);  
        imageView = (ImageView) itemView.findViewById(R.id.image);  
    }  
} 

MainActivity.java class file:

 public class MainActivity extends AppCompatActivity {  
  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
  
        List<Data> data = fill_with_data();  
  
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);  
        RecyclerView_Adapter adapter = new RecyclerView_Adapter(data, getApplication());  
        recyclerView.setAdapter(adapter);  
        recyclerView.setLayoutManager(new LinearLayoutManager(this));  
  
    }  
  
    public List<Data> fill_with_data() {  
  
        List<Data> data = new ArrayList<>();  
        data.add(new Data("Android", R.drawable.c));  
        data.add(new Data("Kotlin", R.drawable.cc));  
		data.add(new Data("Kotlin", R.drawable.ccc));  
        return data; 
    }  
} 


September 22, 20203 minutesauthorPankaj Valani
post

Introduction

You can only develop products and services that are very effective if you pay attention to the needs of your customers and prospects. One way to understand exactly what your customers want is through research and surveys.

1. Understand your customers

You can only develop products and services that will be a big hit if you pay attention to the needs of your customers and prospects. One way to understand exactly what your customers want is through research and surveys. You should constantly invite them to give honest, brutal feedback.

Reviews and surveys are the best way to get into the minds of your customers. This makes it easier for you to develop products and services that are appropriate to the current demands of the market. Moreover, it helps you understand the area in which your company needs to improve.

2. Improving customer service

If you do not provide quality customer service, it will be difficult to satisfy your customers even if you have an excellent product or service. This aspect of the business is about taking extra steps to make them feel special. Let your customers know that they have value. If they have a problem, make sure you address them immediately. If they have questions, take the time to answer.

They should not feel that things are difficult for them if they raise specific issues. Social media is the best way to listen to and understand your customers. If they find customer service satisfactory, they may also recommend buying others from your business.

3. Establish loyalty

It takes time to encourage customers to come and buy what you offer. But just buying them is not enough. You need to promote loyalty. Considering there are other competitors who can offer them better, you want them to stay loyal to you. Don’t be satisfied just because you already have a lot of loyal customers.

They can easily be attracted to other options and they can leave you. Provide loyalty rewards. If there are discounts and discounts, let these most loyal customers be the first to know. You must make sure your customers know they are appreciated.

4. Focus on professional development

The success of your business also depends on the quality of the employees you hire. Building an effective team is the key to making sure your business grows.

One of the best ways to motivate hardworking employees is to give them a sense of purpose. They should not feel that they have to work just to work.

5. Understand your customers

Find ways to increase the sales of your existing customers It's much cheaper than finding a new one. Even if you can't expand your product line, you can still sell more of your existing product or service to a client you already have. An easy way to do this is by volume discount.

6. Participate in networking events

Take the time to build your networks - it's not what you know but who you know. Networking allows you to build relationships with other people and encourage customers to refer to you through words.

7. Give back to your community

Creating brand awareness in your local community is a great way to attract new business. Consider participating in a sponsorship or community event to enhance your business profile.

We will see more points in our next tutorial.

September 07, 20203 minutesauthorAnkit Kalathiya