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<Number> numbers = new ArrayList<>(); 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...
Here is the simple example of maintaining database using Firebase instead of SQLite in Kotlin Programming Language.
Here is the methods to create document(Like table in SQLite), Add data to document, edit data from document, delete data from document.
Here is the video output of this source code
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
Step 1.
Login into Firebase Console and create your project.Step 2.
Navigate into Database and follow the steps given there.Step 3.
Create your Android project and add the following classpath into root of the project's build.gradle.classpath 'com.google.gms:google-services:3.1.1'
Step 4.
And then add the following plugin into your module's build.gradle.apply plugin: 'com.google.gms.google-services'
Step 5.
And then add the following dependency into your module's build.gradle.implementation 'com.firebaseui:firebase-ui-firestore:3.3.1'That's all you wanted to access the Firebase's Firestore API in your project.
Here is the methods to create document(Like table in SQLite), Add data to document, edit data from document, delete data from document.
Add data to document using Hashmap.
//Create employee using hashmap val employee = HashMap() employee.put("name", "Guna") employee.put("phoneNumber", "1144778855") employee.put("email", "Guna@gmail.com") //Add a new document with a generated ID mFirestore.collection("employees") .add(employee) .addOnSuccessListener({ documentReference -> Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.id) }) .addOnFailureListener({ e -> Log.w(TAG, "Error adding document", e) })
Add data to document using entity.
//Create employee using entity val employee = Employee("Guna", "1144778855", "Guna@gmail.com") //Add a new document with a generated ID mFirestore.collection("employees") .add(employee) .addOnSuccessListener({ documentReference -> Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.id) }) .addOnFailureListener({ e -> Log.w(TAG, "Error adding document", e) })
Edit data from document using entity.
//Create employee using entity val employee = Employee("Gunaseelan", "1144778866", "Gunaseelan@gmail.com") //Edit document with a generated ID mFirestore.collection("employees") .document(documentReference.id)//Generated while adding employee .addOnSuccessListener({ documentReference -> Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.id) }) .addOnFailureListener({ e -> Log.w(TAG, "Error adding document", e) })
Delete data from document
//Add a new document with a generated ID mFirestore.collection("employees") .document(documentReference.id)//Generated while adding employee .delete()
Here is the video output of this source code
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.
Comments
Post a Comment