簡體   English   中英

文本識別器更改保存數據編輯文本的行為

[英]Text recognizer changes the behavior of saving data edit text

我正在使用 2 個 EditText,一個用於標題,另一個用於正文。 我通過文本識別器和標題從我的圖像中獲取正文文本,只需輸入標題即可。 但是當我調用文本識別器的函數然后保存數據時,我的標題文本顯示了一個奇怪的行為,即使我輸入標題也會給我丟失標題的警告對話框。 我不知道為什么使用文本識別器功能,標題編輯文本會向我顯示缺少標題的警報對話框。 這是我的代碼

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

我的文本識別器僅用於正文

 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()))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM