Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

when retrieving a link from realtime database to android studio it adds a tag

so basically when i retrieve a link from my real time database it adds this "{abs=" at the beginning and this "}" at the end which makes picasso unable to load the link.
i tried loading the link by pasting the link directly into picasso and it worked just fine
Here is a copy of my code :

public class MainActivity extends AppCompatActivity {
private Button button;
private TextView tv0, tv1;
private String string;
private ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv0 = findViewById(R.id.textView);
    imageView = findViewById(R.id.imageView);
    tv1 = findViewById(R.id.textView2);
    button = findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("muscles");
            reference.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
                        string = snapshot.getValue().toString();
                    }
                    tv1.setText(string);
                    tv0.setText("{abs=https://firebasestorage.googleapis.com/v0/b/my-application-5272b.appspot.com/o/ts-space-sun-and-solar-viewing-facts-versus-fiction.webp?alt=media&token=264af080-27a5-4177-ade3-6eaf30125383}");
                    Picasso.get().load("https://firebasestorage.googleapis.com/v0/b/my-application-5272b.appspot.com/o/ts-space-sun-and-solar-viewing-facts-versus-fiction.webp?alt=media&token=264af080-27a5-4177-ade3-6eaf30125383").into(imageView);
                }

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

        }
    });
}

and this is the XML code :
`

<android.widget.Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/button"
    android:text="Button"
    android:textColor="@color/white"
    app:layout_constraintBottom_toTopOf="@+id/textView2"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="tt"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toTopOf="@+id/button"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.498"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.593"
    tools:srcCompat="@tools:sample/avatars" />

</androidx.constraintlayout.widget.ConstraintLayout>`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem is here:

public void onDataChange(@NonNull DataSnapshot snapshot) {
    for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
        string = snapshot.getValue().toString();
    }

While you’re looping over the snapshot you get from the database to get to the individual child nodes, you’re actually always getting the value of the parent node.

To fix this:

public void onDataChange(@NonNull DataSnapshot snapshot) {
    for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
        string = dataSnapshot.getValue().toString();
               // 👆
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading