2017-12-14 5 views
0

名前、年齢、性別、誕生日など、FireBaseから取得したユーザーデータをいくつかリストしたいと思います。 FireBaseリスナーがあり、リストがデータベースが変更されるたびに更新する必要があります。Firebaseのカスタムリストビューアアダプタ

これは、私はこれは私が私があまりにもデータベースからリストとイメージしたい可能であれば

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <TextView 
    android:id="@+id/textNameList" 
    android:textSize="25dp" 
    android:textAlignment="textStart" 
    android:text="Name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="start" 
    android:layout_margin="10dp"/> 

<TextView 
    android:id="@+id/textAgeList" 
    android:textSize="15dp" 
    android:textAlignment="textStart" 
    android:text="Age" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="start" 
    android:layout_margin="10dp"/> 
<TextView 
    android:id="@+id/textBirthdayList" 
    android:textSize="15dp" 
    android:textAlignment="textStart" 
    android:text="Birthday" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="start" 
    android:layout_margin="10dp"/> 
<TextView 
    android:id="@+id/textGenderList" 
    android:textSize="15dp" 
    android:textAlignment="textStart" 
    android:text="gender" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="start" 
    android:layout_margin="10dp"/> 


    </RelativeLayout> 

を一覧表示するレイアウトですアダプター

private void list(String Name){ 
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mUser); 
    mListView.setAdapter(arrayAdapter); 
    mUser.add(Name,Age,Gender,Birthday); 
    arrayAdapter.notifyDataSetChanged(); 
} 

にデータを送信される方法です。

+0

使用addValueEventのLISTNERそれは、すべての変更は、そのノード 'ref.addValueEventListener(新しいValueEventListenerに起こる耳を傾けます(){} ' –

+0

ありがとうございますが、問題はListViewアダプタでデータを表示することです –

+0

この最終的なArrayAdapter を初期化する必要がありますarrayAdapter = new ArrayAdapter <>(this android.R.layout.simple_list_item_1、mUser); mListView.setAdapter(arrayAdapter); '(名前、年齢、性別、誕生日); 次に 'arrayAdapter.notifyDataSetChanged();'を設定します –

答えて

0

スナップショットから子データを取得し、下記のようにモデルクラスに解析し、arraylistに追加します。リサイクルビューでモデルクラスをarralistするカスタム・アダプターのためのより多くの参照用

、以下のリンクを参照してください https://www.androidhive.info/2016/01/android-working-with-recycler-view/

関連する問題