0% found this document useful (0 votes)
2 views3 pages

2nd class

This document provides a step-by-step guide on integrating Firebase into an Android Studio project, including creating a Firebase project, adding Firestore, and setting up data models. It details the process for creating, reading, and displaying data using RecyclerView, along with necessary code snippets and configurations. The instructions cover both XML design and Java implementation for managing user input and data retrieval.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

2nd class

This document provides a step-by-step guide on integrating Firebase into an Android Studio project, including creating a Firebase project, adding Firestore, and setting up data models. It details the process for creating, reading, and displaying data using RecyclerView, along with necessary code snippets and configurations. The instructions cover both XML design and Java implementation for managing user input and data retrieval.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

FIREBASE IN ANDORID STUDIO

Adding/download requirements

1. go to firebase console and create a new project ender a name as u want


2. click continue and wait now at first view u able to see (get started by adding
firebase to your app) now click on android logo on this text
3. go to gradle build and copy compony name on defaultConfig
4. click register
5. download json file and paste it to your app dic on android
6. now go to andoird window or slide into upper setting like small graphic and
native to tool or select firebase now click on %database firestore% and on 2. (add
cloud firestore to your app) lick botton on this
7. navigate to build on left corner of your project in firebase web , click on
firebase firestore and build in test mode
8. now edit rules of firestore and write only true and remove all code in the end

THAT's IT NOW MOVE ON NEXT STEP

XML DEGIN or finding in code


1. i use 2 edit text such as name , number+ 1 botton such as AdData
ex -

2. now get instance of 2 edit text or 1 button and create a variable for
findviewbyid(R.id.{id})

3.now create a FirebaseFirestore instance


4. and define FirebaseFirestore.getInstance();

5. create a new java model class for and get instance of name,number
6. now make a black constructor and filled constructor of these instance
7. and make all getter and setter

CREATING DATA

1. go to firebase firestore and click on start collection or write any name


2. set a onclicklissiner on button and get name,number to stings
Ex -

3. under this create a object of your model class u make and use new {your model
class name} ({name},{numer})

4. and write variable name where u get firebase instance . collection and your
collection name on braket . document . set . your variable name of model class
object . add any lisniar

ex-

5. now on braket of your lisnear write add {your lisnear name} and click enter for
auto complete
6.now u get task on function
7. do if task.succesful then toast data added successful , else error
ex-

READ DATA

I will fatch data to recycler view u do as u want:


note - get a recycler view on main xml. get a instance of recyclerview view; and do
view = findviewbyid(R.id.{recyclerview name});

1. make a item file <XML> and degine your layout for recycler view | i first use
linear and 2 textview in that.
ex-

2. after this make a java class for {recyclerviewadaptor}


(recyclerviewadaptor)
1. extends your class with recyclerView.Adaptor
2. and make a class of viewholder extends this with recyclerview.Viewholder
and alt+enter on viewholder and fix.
3. and same alt+enter on your main class {recyclerviewadaptor} and implement
all method

3. now go to mainactivity java class and make a function for getting data i named
it as {getalldata}
ex- public void getalldata()
{

1. now do {firestore instance variable}.collection("{collection name}").{add


a lisnear best is snapshot lisnear}.(new {your lisnear})

2. under this lisnear u get a implemented method know as onevent so on this


function write a if statement that include if error==null

3. get a instance of arrylist<{your model class}> such as allarry;

4. and under function not under if do allarry{your instance name} = new


ArrayList<>(); and allarry.clear();

5. now under if statemanet make a variable of object List<{your model class


name}> addall{variable name }= value.toObject(Usermodel.class);

6. do under statement of if - alldatalist {we create on 4.}.addAll(variable


we create on 5.);

7. do view{on note variable}.setlayoutmanager(new


Linearlayoutmanager(Mainactivity.this));

8. now view.setAdaptor(new recyclerviewadaptor{your adaptor class of


recycler}(Mainactivity.this.allarry{on .3})); and alt+enter on this line and make a
constorector this will redirect u to adaptor class
THEN CALL THIS ON mainactivity like this getalldata();

}
(recyclerviewadaptor) again modification
1. now u see 1 constroctor then these is 1 element present in constructor so
get instance these like arrylist<{model class name}> array;
2. do this.activivy = activity; this.arry= arry;
3. so oncreateviewholder do return new RecyclerViewAdaptor{recycler view
adaptor}(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_name{your
item xml}, parent, false);
4. and on getitemcount return allarry{instance variable on 1.}.size();
5. and on Viewholder class on this get instance of your name email such as
TextView name,email; and under viewholder function on this class
6. write your instance variable name = itemview.findviewbyid(R.id.{text view
name id}); and same with number
7. last step of this read process go to onblindviewholder and write
holder.name{variable where u find id's}.setText(allarry{instace u get first of
arrlist}.get(position).getName{form your usermodel class getter}());

DONE WITH READ

ddddddddddddddddddddddawerwearsfsdf

You might also like