0

The problem seems really confusing to me. I try to compare value at 0 index from a String list to uID.toString() and somehow it returns that these String differs from each other. I might not know how it works and actually haven't found a solution yet.

Picture of database

How it looks like in the console

Thats my code:

participateButton = findViewById(R.id.button2);
    participateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FirebaseDatabase.getInstance().getReference("Sports").child("Running").child(getIntent().getStringExtra("id")).child("teammateID").addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    ArrayList<String> list = (ArrayList<String>)snapshot.getValue();
                    Log.d("TAG", list.get(0));
                    Log.d("TAG", FirebaseAuth.getInstance().getUid().toString());
                    Log.d("TAG", Boolean.toString(list.get(0)!=FirebaseAuth.getInstance().getUid().toString()));
                    if(list.get(0) != FirebaseAuth.getInstance().getUid().toString() && list.size() < 2){
                        list.add(FirebaseAuth.getInstance().getUid());
                        FirebaseDatabase.getInstance().getReference("Sports").child("Running").child(getIntent().getStringExtra("id")).child("teammateID").setValue(list);
                    }
                    else{
                        Toast.makeText(v.getContext(), "You are already signed!", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError error) {

                }
            });
        }
    });
juske xd
  • 21
  • 4

0 Answers0