I have an adapter that shows the users that are passed to a list, testData is the List variable
adapter = new SwipeDeckAdapter(testData, getContext());
if (cardStack != null) {
cardStack.setAdapter(adapter);
}
i add the data from FirebaseDatabase and i try to Iterate Randomly but just pass the first value of the Database, this is my structure
"ListaTrabajadores" : {
"TrabajadoresH" : {
"Ecuador" : {
"Quito" : {
"6fvnKNboraZNIecImpAFtrtdwZA3" : {
"id" : "6fvnKNboraZNIecImpAFtrtdwZA3"
},
"8nhcInO7A2eODlz8MS3LuMwXONj2" : {
"id" : "8nhcInO7A2eODlz8MS3LuMwXONj2"
},
"DOPPWREd1uZoYRQr5wdbiUz8d4N2" : {
"id" : "DOPPWREd1uZoYRQr5wdbiUz8d4N2"
}
}
}
}
}
my code just shows the First Id and just shows the first User this is the first ID
"6fvnKNboraZNIecImpAFtrtdwZA3" : {
"id" : "6fvnKNboraZNIecImpAFtrtdwZA3"
this is my code to iterate over firebase and add the data in the List
private void getDataMale() {
if (ciudadX != null && paisX != null) {
FirebaseUtils.getMeetPeopleListCitySexoMasculinoReference(paisX, ciudadX).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getChildrenCount() >= 1) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
MeetList ml = snapshot.getValue(MeetList.class);
if (ml.getID().equals(firebaseUser.getUid())) {
// nothing, are you
}else{
testData.add(ml);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (!getActivity().isDestroyed()) {
adapter.notifyDataSetChanged();
}else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// nada
}
return;
}
}
}
}else if (dataSnapshot.getChildrenCount() == 0) {
mLinearAvisoVacio.setVisibility(View.VISIBLE);
mTextViewAviso.setText("Por el momento no hemos encontrado a nadie en tu ciudad, vuelve mas tarde");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else {
mTextViewAviso.setText("No hemos podido encontrar tu ciudad, activa el gps o intentalo mas tarde");
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.Theme_AppCompat_Light_Dialog).create();
alertDialog.setTitle("No podemos encontrar tu ciudad, intentalo mas tarde");
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok ", new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, int which) {
dialog.dismiss();
mLinearAvisoVacio.setVisibility(View.VISIBLE);
}
});
alertDialog.show();
}
}
I need to iterate Randomly to add to the list and in the list Shows the user randomly
Aucun commentaire:
Enregistrer un commentaire