0

I just wanna link what the user types in the ACTV, to the name in my Realtime Database, so that i can load the value of that name using Glide, and display the downloadurl value in my app after clicking my button. But right now, nothing is being displayed.

public class Translate extends AppCompatActivity {

    private static final String TAG = "Translate";


    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    DatabaseReference firebaseDatabase = rootRef.child("main");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_translate);

        final Button button  = (Button)findViewById(R.id.button3);
        final ImageView imageView = findViewById(R.id.imageView1);
        final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);

        String[] suggest = getResources().getStringArray(R.array.array);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, suggest);
        textView.setAdapter(adapter);


        firebaseDatabase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull final DataSnapshot dataSnapshot) {
                for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
                    final String source = textView.getText().toString();
                    final String message = childSnapshot.getKey();


                            button.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    if(source==message){
                                        GlideApp.with(Translate.this).load(firebaseDatabase.child(message)).placeholder(R.drawable.ic_launcher_background).into(imageView);
                                    }


                                }
                            });

                        }


                    }


                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError) {
                        Log.d(TAG, databaseError.getMessage());
                    }
                });

            }

        }

My database is as below :- enter image description here

I'm trying to link match what the user types in to the database using the if statement if(source==message), but i think that is the wrong way.

Any help is appreciated thank you.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Wolfiebae
  • 395
  • 1
  • 5
  • 19
  • You're trying to compare two strings with `f(source==message){`. String comparisons in Java should use `equals`. See https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – Frank van Puffelen Nov 09 '19 at 14:36
  • The problem is not with the equals. The issue is still the same even after me changing it. I hope you do reopen this question. – Wolfiebae Nov 09 '19 at 15:46
  • Please update your question to show the corrected code, as the string comparison was definitely a possible cause of this problem. You'll also want to spend some time debugging, stepping through the code, setting breakpoints, etc, and updating your question with information about exactly what line doesn't do what you expect it to do. A problem statement like "nothing is being displayed" is just too broad for us to be able to help efficiently. – Frank van Puffelen Nov 09 '19 at 17:22

0 Answers0