I am new to firebase, so some things are still a bit confusing to me.
I have an array: var spinnerArray = arrayOf("Dumbell", "Punching Bag", "Yoga Ball", "Skipping Rope")
which I then pass to a spinner. All that is working. Although, now I want to take it to the next level, which is instead of populating the spinner with the strings I added to the array, I want it to pass the data I have on my firebase database. Reason is, some items have subitems, so I need to use objects instead.
I really don't know how to go around and replace this. Could you please help me
I have already my app connected to the realtime database.
Thanks
{
"KitList" : {
"kettle" : {
"10KG" : "10KG",
"5KG" : "5KG"
},
"punchBag" : "punch bag",
"sandbag" : "sandbag"
}
}
Someone told me I shouldn't have the value equal to the key?
This is my model
class KitList(val title: String) {
override fun toString(): String {
return super.toString()
}}
This is the activity where the spinner is:
class NewKitListActivity : AppCompatActivity() {
var database = FirebaseDatabase.getInstance()
var myRef = database.getReference("KitList")
var spinnerArray = arrayOf("Dumbell", "Punching Bag", "Yoga Ball", "Skipping Rope")
inner class Item {
var IdItem: Int = 0
var Item: String? = null
var SubItems: ArrayList<Item>? = null
}
var newKitList = mutableListOf<String>()
val selectedItems: MutableList<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_kit_list)
var context = this;
var addButton = addKitItemBtn
val spinner = newKitItemSpinner
val spinnerArrayAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray)
//selected item will look like a spinner set from XML
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = spinnerArrayAdapter
val kitList = newKistListView
val listViewAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, newKitList)
kitList.adapter = listViewAdapter
addButton.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
val selectedItem = spinner.selectedItem.toString()
newKitList.add(selectedItem)
listViewAdapter.notifyDataSetChanged()
}
})}}