創建用戶配置文件的數據編輯屏幕。目的是檢索保存在Firebase數據庫中的數據,並將其顯示在EditText中。數據庫數據已經建議供用戶編輯或不編輯,可選。在EditText中檢索並顯示Firebase數據並再次編輯內容保存
EXAMPLE:
Firebase Database
- users
--iduser
----name
----lastname
Screen Example:
Fields:
- EditText1 (mName)
- EditText2 (mLastName)
我想是這樣的:
MainActivity:
private EditText mName;
private EditText mLastName;
private DatabaseReference mDatabaseUsers;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Dashboard");
setSupportActionBar(toolbar);
mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users");
/*User logged in*/
final String user_id = mAuth.getCurrentUser().getUid();
mName = (EditText) findViewById(R.id.edtName);
mLastName = (EditText) findViewById(R.id.edtLastName);
/*I have already created a String to capture the logged-in user ID because I need to access only those user's data.*/
/* I've got this far, I need help to set the value in EditText that will be displayed. Thank you!!*/
mDatabaseUsers.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
的目的是設置在EditText上的內容,就像這樣:mName.setText( 「銀行資料」,TextView.BufferType.EDITABLE);
然後,將更改的數據保存回數據庫。