I'm learning how to use FirebaseVisionTextRecognizer, is't possible to insert few blocks of text to multiple TextView?
The link is where I'm getting started and learning. It worked and is displaying all text into 1 Textview. Then what if image has 4 blocks of texts, is't possible to seperate those 4 blocks of text into 4 different Textview? much help appreciated :) thanks. https://www.youtube.com/watch?v=T0273WiUQPI
private void processText(FirebaseVisionText text) {
List<FirebaseVisionText.TextBlock> blocks = text.getTextBlocks();
//check if list is empty
if (blocks.size() == 0) {
Toast.makeText(this, "empty text", Toast.LENGTH_SHORT).show();
return;
}
//for loop the Textblock and insert text to textview
for (FirebaseVisionText.TextBlock textBlock : text.getTextBlocks()) {
String sText = textBlock.getText();
textView.setText(sText);
}
}
****Update****
**XML Code**
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_ml_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".FirebaseTextML">
<LinearLayout
android:id="@+id/ll_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/cameraButton"
android:layout_width="0dp"
android:layout_height="72dp"
android:layout_marginStart="44dp"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="camera" />
<TextView
android:id="@+id/detectButton"
android:layout_width="0dp"
android:layout_height="72dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="44dp"
android:layout_weight="1"
android:background="@color/colorPrimary"
android:gravity="center"
android:text="detec" />
</LinearLayout>
<ImageView
android:id="@+id/iv_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll_text"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:scaleType="fitXY" />
<LinearLayout
android:id="@+id/ll_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ll_buttons"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/tv_show_text_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:textSize="20dp" />
<TextView
android:id="@+id/tv_show_text_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:textSize="20dp" />
<TextView
android:id="@+id/tv_show_text_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:textSize="20dp" />
</LinearLayout>
</RelativeLayout>
**Java code**
Declaration
LinearLayout mLlView;
Context mContext;
private void processText(FirebaseVisionText text) {
mLlView.removeAllViews();
// create a list to store the textblocks
List<FirebaseVisionText.TextBlock> blocks = text.getTextBlocks();
if (blocks.size() == 0) {
Toast.makeText(this, "empty text", Toast.LENGTH_SHORT).show();
return;
}
mContext = this;
for (FirebaseVisionText.TextBlock textBlock : text.getTextBlocks()) {
String sText = textBlock.getText();
TextView tv = new TextView(mContext);
tv.setText(sText);
mLlView.addView(tv);
}
}
Result i able to split the texts by blocks, but how do I insert them into multiple textview?
Expected Result: