java - 按钮无法点击
问题描述
像这样更改代码后,无法单击该按钮。在我更改之前,可以单击该按钮。顺便说一句,我的错误在哪里?
代码 :
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
}
}
}
}
});
}
解决方案
检查下面的代码工作正常,我也用打印吐司和方法测试过。
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
}
}
}
}
});
}
}
推荐阅读
- c# - RavenDB 4.x 替代 EscapeQueryOptions.RawQuery?
- jquery - Hibernate Search:如何查询父类中的字段?
- routes - 使用常规路由时没有大张旗鼓的操作
- machine-learning - 归一化会降低集成方法的模型性能吗?
- r - 在命名矩阵内添加列
- zoho - 自定义模块的可打印模板
- javascript - 如何在 jsplumb angular 中生成组并在 angular 7 中创建组后动态添加节点
- html - Angular 9 中的顶点图表
- github - 在 githubactions 中创建拉取请求时运行特定作业
- c# - MongoDb 更新嵌套数组项