2016-11-19 10 views
0

人口に関するヘルプが必要です。私は "お店"からすべての子供を取得する必要がありますが、傾ける。解決する方法を知っている人は助けてください。私に正しい配列を与えるメッセージを印刷している間、私はそれをListViewに実装できません。Androidファイヤーベースの人口リストビュー

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_dealer_list_view); 

    mListView = (ListView) findViewById(R.id.dealer_listView); 

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

    ref.addListenerForSingleValueEvent(new ValueEventListener() { 
     @Override 
     public void onDataChange(DataSnapshot dataSnapshot) { 
      DataSnapshot friendsSnapshot = dataSnapshot.child("Shops"); 
      for (DataSnapshot friendSnapshot : friendsSnapshot.getChildren()) { 


       String message = friendSnapshot.child("Dealer").getValue(String.class); 
       System.out.println(message); 

       DatabaseReference ref = FirebaseDatabase.getInstance().getReferenceFromUrl("My URl"+message); 

       FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>(DealerListView.this, 
         String.class, 
         android.R.layout.simple_list_item_1, 
         ref) { 

        @Override 
        protected void populateView(View v, String s, int i) { 

    TextView textView = (TextView) v.findViewById(android.R.id.text1); 
         textView.setText(s); 
        } 
       }; 
       mListView.setAdapter(adapter); 
      } 
     } 
     @Override 
     public void onCancelled(DatabaseError databaseError) { 
     } 
    }); 
} 

更新

- Shops 
     -AAA 
      Dealer: "AAA" 
      Email: "[email protected]" 
      SAP: "D666" 
     -BBB 
      Dealer: "BBB" 
      Email: "[email protected]" 
      SAP:  "D333" 
     -CCC 
      Dealer: "BBB" 
      Email: "[email protected]" 
      SAP:  "D222" 
+0

Dealerプロパティの値を抽出し、このコードを持つので

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Shops"); FirebaseListAdapter<String> adapter = new FirebaseListAdapter<String>( DealerListView.this, String.class, android.R.layout.simple_list_item_1, ref) { protected void populateView(View v, String s, int i) { TextView textView = (TextView) v.findViewById(android.R.id.text1); textView.setText(s); } protected String parseSnapshot(DataSnapshot snapshot) { return snapshot.child("Dealer").getValue(String.class); } }; mListView.setAdapter(adapter); 

:これはあなたが必要とするだけのコードでなければなりませんこのコードがアクセスしているJSONの最小スニペット(テキストとして、スクリーンショットなし) –

+0

私の投稿を更新しました – Rufat

+0

ここでは、ListViewとRecyclerViewを使った完璧な例が見つかります: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md – Anfuca

答えて

1

あなたの問題を過度に複雑だと思われます。あなたが含まれるようにあなたの質問を編集してくださいショップのスナップショットのリストを持っているし、各スナップショットのparseSnapshot

+0

ありがとうございます。リストビューは正しい行数を返しますが、表示されますが空ではなく "Dealer"という名前はありません。 – Rufat

+0

私はこの抽出の例を得ることができます、私はJavaで新しいです、それは私が正確に何をしなければならないか理解するのに役立ちます。前もってありがとうございます – Rufat

+0

デバッガでコードを実行し、 'parseSnapshot()'で何を得るのかを見たいでしょう。 –