Reeal Time Data Send in FireBase(Multiple Data).

  

          Reeal Time Data Send in FireBase(Multiple Data).

 

Xml Code :-

<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"
    
tools:context=".Classwork">
    <
ScrollView
        
android:layout_width="match_parent"

        
android:layout_height="wrap_content">
        <
LinearLayout
            
android:orientation="vertical"
            
android:layout_width="wrap_content"
            
android:layout_height="wrap_content">
            <
GridLayout
                
android:layout_width="match_parent"
                
android:layout_height="match_parent"
                
android:layout_below="@+id/text1"

                
android:columnCount="15"
                
android:rowCount="15">

                <
androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    
android:layout_width="match_parent"
                    
android:layout_height="wrap_content"
                    
android:layout_row="0"
                    
android:layout_column="0"
                    
android:layout_margin="10dp"
                    
card_view:cardCornerRadius="8dp"
                    
card_view:cardElevation="8dp">

                    <
LinearLayout
                        
android:layout_width="match_parent"
                        
android:layout_height="match_parent"
                        
android:weightSum="2"
                        
android:orientation="vertical">

                        <
RelativeLayout
                            
android:layout_width="match_parent"
                            
android:layout_weight="2"
                            
android:orientation="vertical"
                            
android:layout_height="match_parent">
                            <
EditText
                                
android:id="@+id/subject"
                                
android:textSize="25sp"
                                
android:layout_width="wrap_content"
                                
android:layout_height="wrap_content"
                                
android:hint="Subject"/>
                            <
EditText
                                
android:id="@+id/date"
                                
android:textSize="25sp"
                                
android:layout_alignParentRight="true"
                                
android:layout_width="wrap_content"
                                
android:layout_height="wrap_content"
                                
android:hint="date"/>
                        </
RelativeLayout>

                        <
LinearLayout
                            
android:orientation="vertical"
                            
android:layout_width="match_parent"
                            
android:layout_height="wrap_content">
                            <
Button
                                
android:layout_width="match_parent"
                                
android:layout_height="2dp"/>

                        </
LinearLayout>
                        <
RelativeLayout
                            
android:layout_width="wrap_content"
                            
android:layout_height="wrap_content">
                            <
EditText
                                
android:id="@+id/title"
                                
android:textSize="25sp"
                                
android:layout_width="wrap_content"
                                
android:layout_height="wrap_content"
                                
android:hint="Title : 1"/>
                            <
EditText
                                
android:id="@+id/teachername"
                                
android:textSize="25sp"
                                
android:layout_alignParentRight="true"
                                
android:layout_width="wrap_content"
                                
android:layout_height="wrap_content"
                                
android:hint="Teacher name"/>
                        </
RelativeLayout>
                        <
LinearLayout
                            
android:orientation="vertical"
                            
android:layout_width="match_parent"
                            
android:layout_height="wrap_content">
                            <
TextView
                                
android:textSize="25sp"
                                
android:layout_width="wrap_content"
                                
android:layout_height="wrap_content"
                                
android:text="Write Notes-"/>
                            <
EditText
                                
android:id="@+id/decription"
                                
android:layout_marginLeft="5dp"
                                
android:layout_gravity="center"
                                
android:textSize="15sp"
                                
android:layout_width="match_parent"
                                
android:layout_height="wrap_content"
                                
android:hint="write notes with number"/>


                        </
LinearLayout>
                        <
LinearLayout

                            
android:layout_width="wrap_content"
                            
android:layout_height="wrap_content">
                            <
Button
                                
android:onClick="process"
                                
android:id="@+id/uploadclasswork"
                                
android:text="Upload"
                                
android:layout_width="wrap_content"
                                
android:layout_height="60dp"
                                
android:src="@mipmap/ic_launcher"/>

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


            </
GridLayout>

        </
LinearLayout>

    </
ScrollView>



</
LinearLayout>

 

 

Java Code :-

 

package com.niranjan.youtuberegisterlogin;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
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.ValueEventListener;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap;
import java.util.Map;

public class Classwork extends AppCompatActivity {
    EditText 
subject,data,title,teachername,description;
    Button 
upload;



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

    }


    
public void process(View view) {
        
subject=findViewById(R.id.subject);
        
data=findViewById(R.id.date);
        
title=findViewById(R.id.title);
        
teachername=findViewById(R.id.teachername);
        
description=findViewById(R.id.decription);


        String sb=
subject.getText().toString().trim();
        String da=
data.getText().toString().trim();
        String ti=
title.getText().toString().trim();
        String ta=
teachername.getText().toString().trim();
        String ds=
description.getText().toString().trim();

        classworkholder obj = 
new classworkholder(sb,da,ti,ta,ds);
        FirebaseDatabase db = FirebaseDatabase.getInstance();
        DatabaseReference node = db.getReference(
"Classwork");
        node.child(sb).setValue(obj);
        
subject.setText("");
        
data.setText("");
        
title.setText("");
        
teachername.setText("");
        
description.setText("");
        Toast.makeText(
this"Data inserted", Toast.LENGTH_SHORT).show();
    }
}

 

 

 

 

Only Java Files :-

 

package com.niranjan.youtuberegisterlogin;

public class classworkholder {

    String 
subject,data,title,teachername,description;

    
public classworkholder() {
    }

    
public classworkholder(String subject, String data, String title, String teachername, String description) {
        
this.subject = subject;
        
this.data = data;
        
this.title = title;
        
this.teachername = teachername;
        
this.description = description;
    }

    
public String getSubject() {
        
return subject;
    }

    
public void setSubject(String subject) {
        
this.subject = subject;
    }

    
public String getData() {
        
return data;
    }

    
public void setData(String data) {
        
this.data = data;
    }

    
public String getTitle() {
        
return title;
    }

    
public void setTitle(String title) {
        
this.title = title;
    }

    
public String getTeachername() {
        
return teachername;
    }

    
public void setTeachername(String teachername) {
        
this.teachername = teachername;
    }

    
public String getDescription() {
        
return description;
    }

    
public void setDescription(String description) {
        
this.description = description;
    }
}

Comments

Popular posts from this blog

Gride View in Firebase

Register in kotlin

Check Permission in Android Studio