按钮无法点击

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


代码 :


    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

                    }

                }

            }

        }

    });

}


莫回无
浏览 122回答 1
1回答

慕的地6264312

检查下面的代码工作正常,我也用打印吐司和方法进行了测试。public class MainActivity extends AppCompatActivity {&nbsp; &nbsp; private Button buttonNext;&nbsp; &nbsp; @Override&nbsp; &nbsp; protected void onCreate(Bundle savedInstanceState) {&nbsp; &nbsp; &nbsp; &nbsp; super.onCreate(savedInstanceState);&nbsp; &nbsp; &nbsp; &nbsp; setContentView(R.layout.activity_main);&nbsp; &nbsp; &nbsp; &nbsp; buttonNext = (Button) findViewById(R.id.btnNext);&nbsp; &nbsp; &nbsp; &nbsp; buttonNext.setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Toast.makeText(MainActivity.this, "NextClicked", Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //checkBarcode("123");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String getBarcode = scanBarcodeEditText.getText().toString().trim();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (TextUtils.isEmpty(getBarcode)) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanBarcodeEditText.setError("Please enter barcode");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; checkBarcode(getBarcode);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }&nbsp; &nbsp; private void checkBarcode(final String barcode) {&nbsp; &nbsp; &nbsp; &nbsp; //Toast.makeText(MainActivity.this, "Method Call", Toast.LENGTH_SHORT).show();&nbsp; &nbsp; &nbsp; &nbsp; collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onComplete(@NonNull Task<QuerySnapshot> task) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (task.isSuccessful()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (queryDocumentSnapshot.getString("barCode") != null) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; collectionReference.document(queryDocumentSnapshot.getId()).update("productQuantity", FieldValue.increment(1).toString());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Intent to another activity&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Intent to another activity&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java