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());
}
});
}
}
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.