文本识别器更改保存数据编辑文本的行为

Text recognizer changes the behavior of saving data edit text

我正在使用 2 个 EditText,一个用于标题,另一个用于 body 文本。我通过文本识别器和标题从图像中获取 body 文本,只需输入标题即可。但是当我调用文本识别器的功能然后保存数据时,我的标题文本显示出一种奇怪的行为,即使我输入标题也会给我提示缺少标题的警告对话框。我不知道为什么使用文本识别器功能,标题编辑文本会向我显示缺少标题的警告对话框。这是我的代码

private boolean hasTitle() {
    return !titleText.getText().toString().trim().isEmpty();
}

if (hasBody() || hasImage() && !hasTitle()) { // if user missing title
                    AlertDialogNoTitle(); // it should not enter here while i type the title but with recognizer it show alertdialogue. By Log, i am getting the correct text for the title which is not zero
                   // setResult(RESULT_CANCELED, data);
                   // finish();
                } else if (hasTitle()) { // if they have title
                    data.putExtra("USER TITLE", titleText.getText().toString());
                    data.putExtra("USER TEXT", bodyText.getText().toString());
                    if (cardsNamesSingleString != null) {
                        data.putExtra("USER CARDS", cardsNamesSingleString);
                        Util.saveToInternalStorageCard(ArrayImageName, bitmaps);
                    }
                    setResult(RESULT_OK, data);
                    finish();
                } else { // no entry
                    setResult(RESULT_CANCELED, data);
                    finish();
                }
            }

我的文本识别器仅用于 body 文本

 private void detect() {
    //perform text detection here

    //TODO 1. define TextRecognizer
    TextRecognizer recognizer = new TextRecognizer.Builder(NoteActivity.this).build();

    //TODO 2. Get bitmap from imageview
    Bitmap bitmap = ((BitmapDrawable)frontCard.getDrawable()).getBitmap();
    //TODO 3. get frame from bitmap
    Frame frame = new Frame.Builder().setBitmap(bitmap).build();
    //TODO 4. get data from frame
    SparseArray<TextBlock> sparseArray =  recognizer.detect(frame);

    //TODO 5. set data on textview
    StringBuilder stringBuilder = new StringBuilder();

    for(int i=0;i < sparseArray.size(); i++){
        TextBlock tx = sparseArray.get(i);
        stringBuilder.append(tx.getValue());
        stringBuilder.append("\n");
    }
        bodyText.setText(stringBuilder.toString());
    }

试试这个

if ((hasImage() && !hasTitle()) || (hasBody() && !hasTitle()))