I am creating textviews on top of a imageview . I am detecting the text on the image and creating textviews with same position and sizes it works well but there is a problem
ı can only select the text of one textview when ı longclick on the textview .Once ı longclick ı want to be able select all of the textviews is that possible ?
this is my adapter code as you can see ı am creating textviews with the same position and sizes with word boxes that is created by orc so basiclly every word can be selected but ı cant drag the selector to select all sentence
private static List<Bitmap> pdfBitmaps;
public static androidx.appcompat.widget.AppCompatTextView textView;
public static boolean iscopying = false ;
public PdfAdapter(List<Bitmap> pdfBitmaps) {
this.pdfBitmaps = pdfBitmaps;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pdf_page_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, @SuppressLint("RecyclerView") int position) {
Bitmap bitmap = pdfBitmaps.get(position);
holder.imageView.setBitmap(bitmap);
holder.imageView.setImageBitmap(bitmap);
// Clear previous TextViews
holder.textContainer.removeAllViews();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// Add new TextViews
List<String> textValues = MainActivity.allPageTextValuesfordisplay.get(position);
List<Rect> boundingBoxes = MainActivity.allPageBoundingBoxesfordisplay.get(position);
List<Float> textSizes = MainActivity.allPageTextSizesfordisplay.get(position);
for (int i = 0; i < textValues.size(); i++) {
String text = textValues.get(i);
Rect box = boundingBoxes.get(i);
float textSize = textSizes.get(i);
Log.d("sizefortext",""+textSize);
textView = new androidx.appcompat.widget.AppCompatTextView(holder.itemView.getContext());
textView.setTypeface(MainActivity.font);
textView.setTextIsSelectable(true);
textView.setSingleLine(true);
textView.setTextColor(Color.RED); // Set text color to transparent
textView.setTextSize(8);
textView.setText(text);
// textView.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_END);
textView.setBackgroundColor(Color.argb(1, 50, 1, 0)); // Optional: background to visualize the bounding box
// Set position and size based on bounding box
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
box.width(),
box.height()
);
params.leftMargin = box.left;
params.topMargin = box.top+5;
textView.setLayoutParams(params);
holder.textContainer.addView(textView);
Log.d("textview eklendi","yeni bir textview eklendi");
}
}
}, 10000);
}
@Override
public int getItemCount() {
return pdfBitmaps.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
CustomImageView imageView;
FrameLayout textContainer;
public ViewHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.pdf_page_image);
textContainer = itemView.findViewById(R.id.text_container_layout);
}
}