Après avoir changé le code comme ceci, le bouton ne peut pas être cliqué. Avant de changer, le bouton peut être cliqué. Au fait, où est mon erreur?
Code:
buttonNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getBarcode = scanBarcodeEditText.getText().toString().trim();
if (TextUtils.isEmpty(getBarcode)) {
scanBarcodeEditText.setError("Please enter barcode");
} else {
checkBarcode(getBarcode);
}
}
});
private void checkBarcode(final String barcode) {
collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (queryDocumentSnapshot.getString("barCode") != null) {
collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1).toString());
// Intent to another activity
} else {
// Intent to another activity
}
}
}
}
});
}
0
Mr. Robot
4 nov. 2019 à 16:28
2 réponses
private void checkBarcode(final String barcode) {
collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (queryDocumentSnapshot.getString(barCode) != null) {
collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1).toString());
// Intent to another activity
} else {
Toast.makeText(getApplicationContext,"Something wrong..",Toast.LengthLong());
}
}
}
}
});
}
Essaye ça.
0
Ganesh Pokale
4 nov. 2019 à 13:43
Vérifiez le code ci-dessous qui fonctionne correctement. J'ai également testé le toast et la méthode d'impression.
public class MainActivity extends AppCompatActivity {
private Button buttonNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonNext = (Button) findViewById(R.id.btnNext);
buttonNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(MainActivity.this, "NextClicked", Toast.LENGTH_SHORT).show();
//checkBarcode("123");
String getBarcode = scanBarcodeEditText.getText().toString().trim();
if (TextUtils.isEmpty(getBarcode)) {
scanBarcodeEditText.setError("Please enter barcode");
} else {
checkBarcode(getBarcode);
}
}
});
}
private void checkBarcode(final String barcode) {
//Toast.makeText(MainActivity.this, "Method Call", Toast.LENGTH_SHORT).show();
collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
if (queryDocumentSnapshot.getString("barCode") != null) {
collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1).toString());
// Intent to another activity
} else {
// Intent to another activity
}
}
}
}
});
}
}
2
KeTaN
4 nov. 2019 à 14:00