这是我的代码,我用它来保存firebase数据库中的一些EditText
字段。
谁能告诉我我做错了什么?
提前致谢
private FirebaseAuth.AuthStateListener authListener;
private FirebaseAuth auth;
private Button buttonSave;
private Firebase mref;
private EditText editTextName;
private EditText editDOB;
private EditText editphone;
private EditText editcity;
private EditText editclass;
private EditText editboard;
private EditText editschool;
private EditText edithobbies;
private EditText editachievements;
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseAuth.AuthStateListener mAuthListener;
static final String TAG = "YOUR-TAG-NAME";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
Firebase.setAndroidContext(this);
editTextName = (EditText) findViewById(R.id.editTextName);
editDOB = (EditText) findViewById(R.id.editDOB);
editphone = (EditText) findViewById(R.id.editphone);
editcity = (EditText) findViewById(R.id.editcity);
editclass = (EditText) findViewById(R.id.editclass);
editboard = (EditText) findViewById(R.id.editboard);
editschool = (EditText) findViewById(R.id.editschool);
edithobbies = (EditText) findViewById(R.id.edithobbies);
editachievements = (EditText) findViewById(R.id.editachievements);
mref = new Firebase("http://***********.firebaseio.com/Users");
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
Log.d(TAG, "onAuthStateChanged:signed_out");
}
// ...
}
};
FirebaseUser userID = FirebaseAuth.getInstance().getCurrentUser();
if (userID != null) {
buttonSave = (Button) findViewById(R.id.buttonSave);
System.out.println("userID:"+ userID);
buttonSave.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick (View view){
String name = editTextName.getText().toString();
Firebase Childref1 = mref.child("Name");
System.out.println("nameis:"+ name);
Childref1.setValue(name , new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
System.out.println("completedcall");
if (firebaseError != null) {
System.out.println("DataNotSaved" + firebaseError.getMessage());
} else {
System.out.println("DataSaved");
}
}
});
.
.
.
.
//similarily for other fields
尝试功能仅执行此功能
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
System.out.println("completedcall");
}
未打印完成电话
答案 0 :(得分:1)