2017-08-10 7 views
0

私のデータベースのデータをCardviewに表示しようとしています。それは機能していますが、個々のカードにデータを表示する代わりに、すべてのデータが1つのカードにまとめられています。これの理由は何でしょうか? FirebaseAndroid - firebaseのカードビューにデータを表示

これは、それがどのように見えるかです::

enter image description here

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerview" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

Card.xml(レイアウトファイル)

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/text1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <TextView 
     android:id="@+id/text2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" /> 

    <TextView 
     android:id="@+id/text3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

は、これは私のFirebaseデータベースがどのように見えるかです

フラグメントクラス:

public class HistoryFragment extends Fragment { 

RecyclerView recyclerView; 
DatabaseReference myRef; 
FirebaseAuth mAuth; 


@Override 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View rootView = inflater.inflate(R.layout.fragment_history, container, false); 

    mAuth = FirebaseAuth.getInstance(); 
    final FirebaseUser user = mAuth.getCurrentUser(); 


    myRef = FirebaseDatabase.getInstance().getReference().child("Users").child(user.getDisplayName()); 

    recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview); 
    recyclerView.setHasFixedSize(true); 
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); 

    FirebaseRecyclerAdapter<Bet, BetViewHolder> adapter = new FirebaseRecyclerAdapter<Bet, BetViewHolder>(
      Bet.class, 
      R.layout.history_individual_row, 
      BetViewHolder.class, 
      myRef 
    ) { 
     @Override 
     protected void populateViewHolder(BetViewHolder viewHolder, Bet model, int position) { 
      viewHolder.setTextDescription(model.desc()); 
      viewHolder.setTitle(model.title()); 
      viewHolder.setTextFlow(model.flow()); 
     } 
    }; 

    recyclerView.setAdapter(adapter); 


    return rootView; 
} 

public static class BetViewHolder extends RecyclerView.ViewHolder { 
    TextView text1View, text2View, text3View; 

    public BetViewHolder(View itemView) { 
     super(itemView); 
     text1View= (TextView) itemView.findViewById(R.id.text1); 
     text2View= (TextView) itemView.findViewById(R.id.text2); 
     text3View= (TextView) itemView.findViewById(R.id.text3); 
    } 

    public void setTextDescription(String desc) { 
     text1View.setText(desc); 
    } 


    public void setTitle(String title) { 
     text2View.setText(title); 
    } 

    public void setTextFlow(String flow) { 
     text3View.setText(flow); 

    } 
} 

} 
+0

レイアウトファイルを追加し、データを表示するコードを追加できますか? –

+0

はい、コード – John

答えて

0

私は問題があなたのfirebase JSON形式であると思います - あなたは要素のない配列を格納するには、複数の子フィールドを持つAA一つの大きなオブジェクト(ユーザー)を格納するので、それはあなたに戻りますあなたのすべてのオブジェクトを一つの大きなオブジェクトとして。

以前は同じ問題がありました。そのため、Firebaseというものを見つけることをお勧めします。これは、(私の意見では)複雑なオブジェクトを格納する正しい方法ではありません(1対多の関係やあなたが望むように内部配列)、それは実際にデータベースがないので、あなたのjsonを保存するだけです。

さらに、どのようなタイプの検索やクエリも実装することはできません。

私の答えは:私はfirebaseの理由は、通常のsql(またはnoSql)データベースで通常のサーバーに変更します。

+0

で質問を編集しましたFirebaseはnoSqlデータベースです – John

関連する問題