I am not getting my Database name items in my autocompletetextview. I am not sure what is wrong with my code.
Here is my small firebase Database.
[ null, { "Coordinaat" : 75,
"Naam" : "Cream"
}, {
"Coordinaat" : 47885,
"Naam" : "Cacao"
}, {
"Coordinaat" : 48456,
"Naam" : "Cola"
}, {
"Coordinaat" : 25164,
"Naam" : "Yoghurt"
}, {
"Coordinaat" : 54,
"Naam " : "Carrot"
}, {
"Coordinaat" : 57,
"Naam" : "Yum"
} ]
Here is my ProductClass.
public class Product {
public String name;
public int coordinaat;
public Product()
{
}
public Product(String name, int coordinaat)
{
this.name = name;
this.coordinaat = coordinaat;
}
public void setcoordinaat(int coordinaat) {
this.coordinaat = coordinaat;
}
public void setname(String name)
{
this.name = name;
}
public String getname()
{
return name;
}
public int getcoordinaat()
{
return coordinaat;
}
}
Here is my activity code.
public class tweede extends AppCompatActivity {
private static final String[] producten = new String[] { "Yoghurt",
"Cream", "Cacao", "Cola", "Yummy", "Chocolate" , "Can" , "Cannabis" , "Caramel", "Carrot", "Coconut" };
DatabaseReference databaseProducten;
//ListView lstviewProducten;
List <Product> lstPro = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tweede);
databaseProducten = FirebaseDatabase.getInstance().getReference();
AutocmpleteMeth();
// lstviewProducten = (ListView) findViewById(R.id.listView2);
}
@Override
protected void onStart() {
super.onStart();
databaseProducten.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
lstPro.clear();
for(DataSnapshot productenSnapshot : dataSnapshot.getChildren())
{
Product product = productenSnapshot.getValue(Product.class);
lstPro.add(product);
}
AutocmpleteMeth(); }
@Override public void onCancelled(DatabaseError databaseError) {
}
});
}
public void AutocmpleteMeth()
{
// Hieronder is het code voor Autocomplete [BEGIN]
AutoCompleteTextView ACTV;
ACTV=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView2);
ArrayAdapter<Product> adapter = new ArrayAdapter<Product>(this, android.R.layout.simple_dropdown_item_1line, lstPro);
ACTV.setAdapter(adapter);
ACTV.setThreshold(1);
//Autocmplete [END]
}
}
That what i am getting on my phone..