0
I’m building an application that’s just an information filter that’s in the json of the firebase database. My headache is being where I’m going to apply the search code! for now it’s like this:
public class MainActivity extends AppCompatActivity {
private static final String[] setor = {"Modelagem", "Corte", "Silk", "Bordado", "Produção", "Acabamento", "Embalagem", "Lavanderia", "Facção"};
ArrayAdapter<String> Asetor;
Spinner spinner;
Button buscar;
Firebase objetoRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//SPINNER
Asetor = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, setor);
//PEGANDO ITENS DO SPINNER
spinner = (Spinner) findViewById(R.id.setor);
spinner.setAdapter(Asetor);
//BUTTON BUSCAR
buscar = (Button) findViewById(R.id.buscar);
//FIREBASE
Firebase.setAndroidContext(this);
objetoRef = new Firebase("https://rastro-4ed10.firebaseio.com/");
objetoRef.addValueEventListener(new ValueEventListener() {
@Override //CLASS UTILIZADA PARA ALTERAR UM TEXTVIEW CONFORME O BANCO
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
Log.d(TAG, "value is: "+ value);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
I do not know if I do inside onDataChange, or if I do in Main_activity where the result will appear... There are 3 search fields one Spinner and two Edittext.
This will depend on it. If this filter is going to grow and become more complex, I advise you to create a class to receive data from
OnDataChange
and return where the result will appear. Otherwise, you can do everything ononDataChange
even.– Silas Ribeiro
It would only be 3 search fields anyway! If you can give me some ideas of which function to use. " Equals" ?
– Felipe
This will depend on the fields you will work on. I believe that in this case
equals
would already be enough because the return is aString
.– Silas Ribeiro