Im trying to make a autocompletetextview from Firestore database. I already get the data from Firestore and put it in 1 list called autocompleteList. The problem is when I type in the textview, the autocomplete doesn't appear but when I try to add list manually "autocompleteList.add("1 - Jordan") it appears. so what is the problem with my code ? why can't my type value from Firestore appear ?
this is the method:
private void openDialog(){
LayoutInflater li = CreateReceiptActivity.this.getLayoutInflater();
final View v = li.inflate(R.layout.alertdialog_create_receipt, null);
final Builder builder = new Builder(CreateReceiptActivity.this);
builder.setView(v);
final AutoCompleteTextView addItemType = v.findViewById(R.id.alertdialog_receipt_type);
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection("watchlist").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Log.d(Tag.ITEM, document.getId() + "=>" + document.getData());
String type = document.getString("type");
autocompleteList = new ArrayList<String>();
autocompleteList.add(type);
}
ArrayAdapter<String> acadapter = new ArrayAdapter<String>(CreateReceiptActivity.this,
R.layout.list_autocomplete, R.id.autocomplete_itemtype, autocompleteList);
addItemType.setAdapter(acadapter);
} else {
Log.w(Tag.ITEM, "error getting documents", task.getException());
}
}
});
final EditText addItemQty = v.findViewById(R.id.alertdialog_receipt_qty);
final EditText addItemPrice = v.findViewById(R.id.alertdialog_receipt_price);
Button btnSubmit = v.findViewById(R.id.alertdialog_receipt_submit);
addItemType.setText(qrResult);
final AlertDialog alertDialog = builder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button btnScan = v.findViewById(R.id.alertdialog_receipt_scanqr);
btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(CreateReceiptActivity.this, QRScannerActivity.class);
startActivityForResult(i, QR_REQUEST_CODE);
}
});
}
});
alertDialog.show();
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
itemType = addItemType.getText().toString().trim();
itemQty = addItemQty.getText().toString().trim();
itemPrice = addItemPrice.getText().toString().trim();
listReceiptItem = new ListReceiptItem(itemType, itemQty, itemPrice, "0");
receiptItemList.add(listReceiptItem);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
alertDialog.dismiss();
qrResult = null;
Toast.makeText(CreateReceiptActivity.this, "barang tertambah", Toast.LENGTH_SHORT).show();
}
});
}