App2k
Home
Project
Android Studio
Collage Project
Home
Got Single Bucket data in (Textview1,TextView2)
Got Single Bucket data in (Textview1,TextView2)
App Developer
October 11, 2024
1. Activity (activity_main.xml)
1. Activity (mainactivity.java)
package com.example.firebaseexample; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; 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; public class MainActivity extends AppCompatActivity { private TextView textView1, textView2; private FirebaseDatabase database; private DatabaseReference reference; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize TextViews textView1 = findViewById(R.id.textView1); textView2 = findViewById(R.id.textView2); // Initialize Firebase database database = FirebaseDatabase.getInstance(); reference = database.getReference("data"); // Read data from Firebase Realtime Database reference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { // Get values from database String value1 = dataSnapshot.child("text1").getValue(String.class); String value2 = dataSnapshot.child("text2").getValue(String.class); // Set values to TextViews textView1.setText(value1); textView2.setText(value2); } @Override public void onCancelled(@NonNull DatabaseError error) { // Handle possible errors textView1.setText("Failed to load data."); textView2.setText("Failed to load data."); } }); } }
1. Firebase Realtime Database Structure
{ "data": { "text1": "Hello from Firebase!", "text2": "This is another text." } }
Post a Comment
0 Comments
Social Plugin
Most Popular
adb connect 192.168.29.254 cannot connect to 192.168.29.254:5555: No connection could be made because the target machine actively refused it.
June 10, 2025
Contact Us
March 03, 2025
full funcing video player in flutter
May 25, 2025
Facebook
Tags
android studio firebase
android studio firebase realtime database
Firebase
Flutter
How to Save Data to the Firebase Realtime Database
Java
Project
Categories
Flutter
(13)
Java
(2)
Project
(1)
android studio firebase
(1)
Search This Blog
Powered by Blogger
June 2025
3
May 2025
1
April 2025
2
March 2025
12
February 2025
7
December 2024
2
October 2024
9
September 2024
2
Report Abuse
Contact form
0 Comments