快照返回多个值

时间:2020-10-20 22:14:28

标签: java android firebase-realtime-database

我想参加第二个活动,并从firebase中获取一些值。 但是,当我打印它时,它总是返回多个值,只有一个是正确的值,而其他的只是空值。

例如,这是它的打印内容:

$itemArray = array();
$items = 44;

$max_points = 30;

$mid_range = 0 + $items / 2;

$start_count = $mid_range-15;

for( $i=$start_count; $i < 30; $i++ ) {
    $itemArray[] = $yourArray[$i];
}

代码:

null
correct
null
null
null

我认为可能是因为我将DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("StoresData"); reference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot snapshot) { for (final DataSnapshot snapshot1: snapshot.getChildren()){ TextView storenamego = (TextView) content.findViewById(R.id.storenamego); //The next line returns multiple values containing null System.out.println("pleasesee" + snapshot1.child(parkingList.get(position).getStoreid()).child("arname").getValue(String.class)); storenamego.setText(snapshot1.child(parkingList.get(position).getStoreid()).child("arname").getValue(String.class)); storenamego.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(SpecialityListActivityAr.this, LoggedInAr.class); intent.putExtra("pharmacy_name",snapshot1.child(parkingList.get(position).getStoreid()).child("arname").getValue(String.class)); String nameid = getIntent().getStringExtra("nameid"); String specialityid = getIntent().getStringExtra("specialtyid"); intent.putExtra("username", snapshot1.child(parkingList.get(position).getStoreid()).child("username").getValue(String.class)); intent.putExtra("nameid", nameid); System.out.println("NameID:" + nameid); intent.putExtra("supervisor",snapshot1.getKey()); String getname = getIntent().getStringExtra("nameofcus"); intent.putExtra("nameofcus", getname); String special = getIntent().getStringExtra("speciality"); intent.putExtra("asda", special); intent.putExtra("specialtyid", specialityid); String getmob = getIntent().getStringExtra("mob"); intent.putExtra("mob", getmob); intent.putExtra("storephone",snapshot1.child(parkingList.get(position).getStoreid()).child("phone").getValue(String.class)); intent.putExtra("lng", getIntent().getStringExtra("lng")); intent.putExtra("lat", getIntent().getStringExtra("lat")); startActivity(intent); } }); } } @Override public void onCancelled(@NonNull DatabaseError error) { } }); 放在了适配器中。如果是这样,谁能指导我改变我的位置?

Firebase数据库结构:

Database structure

0 个答案:

没有答案