Рет қаралды 18,254
In this video it shows the steps to create your firebase database based Calendar App. This App can be used to store your reminders or events in your firebase database.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: programmerworl... or email at: programmerworld1990@gmail.com
Complete source code and other details/ steps of this video are posted in the below link:
programmerworl...
However, the main Java code is copied below also for reference:
package com.programmerworld.firebasecalendarapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CalendarView;
import android.widget.EditText;
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 CalendarView calendarView;
private EditText editText;
private String stringDateSelected;
private DatabaseReference databaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
calendarView = findViewById(R.id.calendarView);
editText = findViewById(R.id.editText);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int i, int i1, int i2) {
stringDateSelected = Integer.toString(i) + Integer.toString(i1+1) + Integer.toString(i2);
calendarClicked();
}
});
databaseReference = FirebaseDatabase.getInstance().getReference("Calendar");
}
private void calendarClicked(){
databaseReference.child(stringDateSelected).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.getValue() != null){
editText.setText(snapshot.getValue().toString());
}else {
editText.setText("null");
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
public void buttonSaveEvent(View view){
databaseReference.child(stringDateSelected).setValue(editText.getText().toString());
}
}
-