In the last tutorial, I solve the connection with the firebase database.
In this tutorial, I add a new record into the database and I fix the source code to work well with this.
See the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); button = FindViewById<Button>(Resource.Id.button1); this.FindViewById<Button>(Resource.Id.button1).Click += this.Button_Clicked; } void Button_Clicked(System.Object sender, System.EventArgs e) { mytextView = FindViewById<TextView>(Resource.Id.textView1); this.FindViewById<TextView>(Resource.Id.textView1).Text = "Is set!"; recordData = FindViewById<EditText>(Resource.Id.editText1); string conn = "https://xamarinapp-8cccb-default-rtdb.europe-west1.firebasedatabase.app"; FirebaseClient firebaseClient = new Firebase.Database.FirebaseClient(conn); firebaseClient.Child("Records").PostAsync(new MyDatabaseRecord { MyProperty = recordData.Text }); recordData.Text = ""; } |
You can see the result of this source code into the emulator software and the web firebase page: