2017-02-23 25 views
0

私は私の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) { 

     } 

    }); 

は、データベースの構造です:

enter image description here

+0

私はこれに答えることができるかもしれませんが、まず私に聞かせてください。 1つのuidが 'user'と' businessAcc'の両方に値を持つことは可能ですか? – koceeng

+0

私の前の質問の答えが「いいえ」の場合、あなたのコードがうまくいくように見えます。では、正確に何を聞きたいのですか? – koceeng

+1

私は単一のデータベースにマージしました。手間を省くため。 – Kovachx

答えて

0

あなたはissue.Toはあなたの問題を解決しているFirebaseリファレンスを再起動されます。

まず、ルート参照を取得します。

DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference(); 

次に、ルート参照から2つの別個の参照を作成します。

これで、これらの参考資料を使用して作品を作成できます。

+0

まだ動作しません。1つのプロファイルは表示されず、他のプロファイルが表示されます。 – Kovachx

+0

データベース構造を共有できますか? –

+0

編集して追加しました。基本的には、ユーザーIDが通常のユーザーとは異なるユーザーのビジネスユーザーである場合に表示します。 – Kovachx

関連する問題