使用Firebase数据填充Android微调器 [英] Populating Android spinner with Firebase Data
问题描述
在将 propertyAddress
从我的 properties
表填充到 MaintenanceActivity
中的微调框时,我遇到了一些问题.
问题本身不在于代码内,而是与可以使用Firebase控制台进行修改的数据库规则有关.
目前,我的规则如下:
{规则":{维护" : {"$ uid":{".read":"$ uid === auth.uid",".write":"$ uid === auth.uid"}}}}
在记录维护查询时允许基于用户的身份验证.
但是,仅当规则如下时,微调器才会填充propertyAddress:
{规则":{".read":"true",".write":"true"}}
我想知道我需要对规则做些什么,以使我的微调框 spinnerProperty
可以访问数据库的 properties
部分./p>
这是 MaintenanceActivity
的代码摘录:
维护活动
fDatabaseRoot.child("properties").addListenerForSingleValueEvent(new ValueEventListener(){@Override公共无效onDataChange(DataSnapshot dataSnapshot){dataSnapshot.getChildren()至//初始化数组最终List< String>propertyAddressList = new ArrayList< String>();对于(DataSnapshot addressSnapshot:dataSnapshot.getChildren()){字符串propertyAddress = addressSnapshot.child("propertyAddress").getValue(String.class);如果(propertyAddress!= null){propertyAddressList.add(propertyAddress);}}Spinner spinnerProperty =(Spinner)findViewById(R.id.spinnerProperty);ArrayAdapter< String>addressAdapter = new ArrayAdapter< String>(MaintenanceActivity.this,android.R.layout.simple_spinner_item,propertyAddressList);addressAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spinnerProperty.setAdapter(addressAdapter);}@Override公共无效onCancelled(DatabaseError databaseError){}});
这是我的属性表的图像:
在此方面的任何帮助将不胜感激.
同样,与代码本身无关,仅与数据库规则无关.
我已经更新了Firebase数据库的规则,以包括对 properties
节点的读取/写入功能.
{规则":{维护" : {"$ uid":{".read":"$ uid === auth.uid",".write":"$ uid === auth.uid"}},特性" : {".read":是的,".write":false}}}
I am having a few issues populating the propertyAddress
from my properties
table to to a spinner in my MaintenanceActivity
.
The issue itself does not lie within the code, rather with the Database Rules that can be amended using the Firebase Console.
Currently, my rules are like so:
{
"rules": {
"maintenance" : {
"$uid" : {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
Which allows user-based authentication when logging maintenance queries.
However, the spinner will only populate with the propertyAddress when the rules are as follows:
{
"rules": {
".read":"true",
".write": "true"
}
}
I'm wondering what I need to do to my rules in order to allow my spinner, spinnerProperty
, to have access to the properties
part of my DB.
Here is the code extract for MaintenanceActivity
:
MaintenanceActivity
fDatabaseRoot.child("properties").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
dataSnapshot.getChildren() to
// initialize the array
final List<String> propertyAddressList = new ArrayList<String>();
for (DataSnapshot addressSnapshot: dataSnapshot.getChildren()) {
String propertyAddress = addressSnapshot.child("propertyAddress").getValue(String.class);
if (propertyAddress!=null){
propertyAddressList.add(propertyAddress);
}
}
Spinner spinnerProperty = (Spinner) findViewById(R.id.spinnerProperty);
ArrayAdapter<String> addressAdapter = new ArrayAdapter<String>(MaintenanceActivity.this, android.R.layout.simple_spinner_item, propertyAddressList);
addressAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerProperty.setAdapter(addressAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Here is an image of my properties table:
Any help on this would be much appreciated.
Again, not an issue with the code itself, only with the rules of the DB.
I have updated the rules for my Firebase Database to include read/write functionality for the properties
node.
{
"rules": {
"maintenance" : {
"$uid" : {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
},
"properties" : {
".read": true,
".write": false
}
}
}
这篇关于使用Firebase数据填充Android微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!