私は私のProfilePage.classを持っており、ユーザーのプロフィールを表示するつもりですが、2つの異なるタイプのユーザーがいるので問題があります。そのうちの1つは通常のユーザーであり、もう1人はビジネスユーザーです。どのように私はデータベースの子供の両方を呼び出すとxmlレイアウトの特定の情報を表示するユーザーの種類に応じてこれまで私はこれを持っているが、それは正常に動作しません。ここで同時に2つのfirebaseデータベースの子供を取得する
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_page_both);
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference().child("user");
mDatabaseBuisness = FirebaseDatabase.getInstance().getReference().child("businessAcc");
mNormalUserProfilePic = (ImageView) findViewById(R.id.normalUserProfilePic);
mNormalUserEmail = (TextView) findViewById(R.id.normalUserEmail);
mNormalUserProfile = (TextView) findViewById(R.id.normalUserProfile);
mBusinessUserPostcode = (TextView)findViewById(R.id.businessPostcode);
String uid = mAuth.getCurrentUser().getUid();
mDatabase.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String profile_username = (String) dataSnapshot.child("username").getValue();
String profile_image = (String) dataSnapshot.child("image").getValue();
String profile_uid = (String) dataSnapshot.child("uid").getValue();
String profile_email = (String) dataSnapshot.child("email").getValue();
mNormalUserEmail.setText(profile_email);
mNormalUserProfile.setText(profile_username);
Picasso.with(ProfilePageNormalUser.this).load(profile_image).into(mNormalUserProfilePic);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
mDatabaseBuisness.child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String profile_username = (String) dataSnapshot.child("username").getValue();
String profile_image = (String) dataSnapshot.child("image").getValue();
String profile_uid = (String) dataSnapshot.child("uid").getValue();
String profile_email = (String) dataSnapshot.child("email").getValue();
String profile_postcode = (String) dataSnapshot.child("postCode").getValue();
mNormalUserEmail.setText(profile_email);
mNormalUserProfile.setText(profile_username);
mBusinessUserPostcode.setText(profile_postcode);
Picasso.with(ProfilePageNormalUser.this).load(profile_image).into(mNormalUserProfilePic);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
は、データベースの構造です:
私はこれに答えることができるかもしれませんが、まず私に聞かせてください。 1つのuidが 'user'と' businessAcc'の両方に値を持つことは可能ですか? – koceeng
私の前の質問の答えが「いいえ」の場合、あなたのコードがうまくいくように見えます。では、正確に何を聞きたいのですか? – koceeng
私は単一のデータベースにマージしました。手間を省くため。 – Kovachx