0

My listview is from a fragment and I want to pass all the inputted data at once in the listview to firebase. I have not seen any source about "ListView to Firebase" it's usually "From Firebase to ListView" so I have decided to ask this question.

This is what I did temporarily until I find the solution on passing values from ListView to Firebase Realtime Database. I don't know how to put values from ListView to Firebase so what I did is to put items from EditText to Firebase in a click of a button which is not what I needed.

private void AddpackageinfoButton_Click(object sender, EventArgs e)
        {
                if (infonamecrud.add(packageinfonameText.Text) && infoqtycrud.add(packageinfoqtyText.Text))
                {
                    string packageinfoname = packageinfonameText.Text;
                    string packageinfoqty = packageinfoqtyText.Text;

                    Java.Util.HashMap packageinfo = new Java.Util.HashMap();
                    packageinfo.Put("infoName", packageinfoname);
                    packageinfo.Put("infoQty", packageinfoqty);
                    {
                        DatabaseReference newPackageInfoRef = AppDataHelper.GetDatabase().GetReference("packageinfo").Push();
                        newPackageInfoRef.SetValue(packageinfo);
                    }

                    infonameadapter = new ArrayAdapter(this.Activity, Android.Resource.Layout.SimpleListItem1, infoName);
                    packageinfonameListView.Adapter = infonameadapter;
                    infoqtyadapter = new ArrayAdapter(this.Activity, Android.Resource.Layout.SimpleListItem1, infoQty);
                    packageinfoqtyListView.Adapter = infoqtyadapter;
                }
            }
            else
            {
                Toast.MakeText(this.Activity, "Please input all fields!", ToastLength.Long).Show();
            }
        }

FOR MORE DETAILS: This is my layout and the ADD INCLUSIONS Button doesn't have a function. It is for the items in listview to be passed in database all at oncec. This is my layout

This is how it would look like in the firebase. I need them all in one key. This is how it would look in database

What I need is passing all items in listview all at once. I just temporarily applied the hashmap every add button just to fill up the database and but the problem is the retrieval because they would have different key values.

Is there any syntax for this? Thank you so much for future answers. I appreciate it a lot! :)

Zeno
  • 11
  • 3
  • In general, we submit an item one by one to realtime database of Firebase. – Jessie Zhang -MSFT Nov 25 '22 at 06:14
  • Thank you for the reply, is there any syntax to put a custom key wherein (base on the image on my firebase) I could put something in between "packageinfo" and generated key? Is that doable? I could just call the "child" and call all the keys under it? Thank you. – Zeno Nov 25 '22 at 19:43
  • You can use code `firebase .Child("packageinfo")... ` to retrieve above link. But you can also try to use `setValue()` to set the custom key. For more information, you can check thread [Setting custom key when pushing new data to firebase database](https://stackoverflow.com/questions/37483406/setting-custom-key-when-pushing-new-data-to-firebase-database). – Jessie Zhang -MSFT Nov 29 '22 at 08:53

0 Answers0