Skip to main content

Posts

Showing posts from July, 2018

Featured post

Simple RecyclerView example with filter option in Android

Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter. As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUND...

Simple example of using Firebase Cloud Messaging in Android | Kotlin

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost. You can send notification messages to drive user re-engagement and retention. To write your Firebase Cloud Messaging Android client app, use the FirebaseMessaging API and Android Studio 1.4 or higher with Gradle. FCM clients require devices running Android 4.0 or higher that also have the Google Play Store app installed, or an emulator running Android 4.0 with Google APIs. Note that you are not limited to deploying your Android apps through Google Play Store. Set up Firebase and the FCM SDK * If you haven't already, add Firebase to your Android project . * In Android Studio, add the FCM dependency to your app-level build.gradle file: implementation 'com.google.firebase:firebase-messaging:17.1.0' Create a Service that extends FirebaseMessagingService. Here is the full code of FCMService.kt class FCMService : FirebaseMessagingService() { o...

Simple example of using BottomSheetDialog in Android | Kotlin

BottomSheetDialog is simple dialog styled as bottom sheet. BottomSheetDialog implementation is quite simpler and easier than normal Dilaogs. You can just attach view for it and then display it. Here is simple example. This tutorial is developed using kotlin. MainActivity.kt val dialog = BottomSheetDialog(this) val bottomSheet = layoutInflater.inflate(R.layout.bottom_sheet, null) bottomSheet.buttonSubmit.setOnClickListener { dialog.dismiss() } dialog.setContentView(bottomSheet) dialog.show() bottom_sheet.xml &lt?xml version="1.0" encoding="utf-8"?&gt &ltandroid.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/bottomSheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp"&gt &ltTextView ...

Simple example of using BottomSheetBehavior in Android | Kotlin

BottomSheetBehavior is An interaction behavior plugin for a child view of CoordinatorLayout to make it work as a bottom sheet. Bottom sheet is something like sliding a view from bottom to top, you may already seen this design in Google Play Music or VLC media player app. Here is the simple example of using BottomSheetBehavior in Android, code is developed in Kotlin. MainActivity.kt val bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet) bottomSheetBehavior.setBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { override fun onStateChanged(bottomSheet: View, newState: Int) { when (newState) { BottomSheetBehavior.STATE_EXPANDED -> { textBottom.text = getString(R.string.slide_down) //textFull.visibility = View.VISIBLE } BottomSheetBehavior.STATE_COLLAPSED -> { textBottom.text = getString(R.string.slide_up) //textFull.visibility = View.GONE...

Dynamic Grid Count in GridLayoutManager using RecyclerView | Android | Kotlin

Sometime we need RecyclerView filled with dynamic row count. For example, some row has 3 columns, and some has 2 columns, and some should have only one column like that. Here is the simple example of dynamic grid count using GridLayoutManager in RecyclerView. val layoutManager = GridLayoutManager(this, 6) layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { override fun getSpanSize(position: Int): Int { when (position) { 0, 1, 2, 6, 7, 8, 12, 13, 14, 18, 19, 20 -> return 2 3, 4, 9, 10, 15, 16, 21, 22, 24, 25 -> return 3 5, 11, 17, 23 -> return 6 else -> return 2 } } } recyclerView.layoutManager = layoutManager Screenshot: Interesting right? If you are really interested in this code, then please share this post with your friends, also share your feedback as comment here. Thank You