我可以从我的数据库中检索数据firebase
spinner
已满,但我无法保存选中的项目我放线
uaselected = uaSpinner.getSelectedItem().toString().trim();
在OnData更改后保存选中的项但它返回null,因为它在函数OnData更改任何帮助之前首先执行
答案 0 :(得分:1)
使用此方法。
spncountry.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
country_data=spncountry.getSelectedItem().toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
答案 1 :(得分:0)
databasereference = database.getReference();
mAuth = FirebaseAuth.getInstance();
areaSpinner = (Spinner) findViewById(R.id.spinneretab);
databasereference.child("UA_unity").addValueEventListener(new com.google.firebase.database.ValueEventListener() {
@Override
public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
final List<String> etab = new ArrayList<String>();
final List<String> keyunity = new ArrayList<String>();
// uaselected = areaSpinner.getSelectedItem().toString().trim();
for (DataSnapshot child: dataSnapshot.getChildren()) {
nameua = (String) child.child("nom_UA").getValue();
keyua = child.getKey();
// keyunity.add(keyua);
// databasereference.child("Users").child("UA_ID").setValue(keyua);
etab.add(nameua);
}
ArrayAdapter<String> areasAdapter = new ArrayAdapter<String>(add_info_user.this, android.R.layout.simple_spinner_item, etab);
areasAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
areaSpinner.setAdapter(areasAdapter);
uaselected = areaSpinner.getSelectedItem().toString().trim();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}