gpt4 book ai didi

java - 按钮无法点击

转载 作者:行者123 更新时间:2023-12-02 01:15:26 25 4
gpt4 key购买 nike

我这样修改代码后,按钮无法点击。在我更改之前,可以单击该按钮。顺便问一下,我的错误在哪里?

代码:

    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
}
}
}
}
});
}

最佳答案

检查下面的代码是否正常工作,我也使用打印 toast 和方法进行了测试。

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
}
}
}
}
});
}
}

关于java - 按钮无法点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58694428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com