0

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

    }



}
4
  • Can you show some code? Commented Aug 28 at 19:08
  • ı edited the question with code this is my adapter code to create the ımageviews as you can see ı am creating the textviews on top of the imageview and it works perfectly but ı just can select one word at a time because they are all different textviews
    – Tndstn
    Commented Aug 28 at 19:25
  • Can you give more information about the intent of selecting the TextViews? For example, would you like to be able to copy all of the text to the clipboard?
    – TGruenwald
    Commented Aug 29 at 2:46
  • I am trying to create a pdf editor app and i want to be able to select and copy the text on the page like a regular pdf app
    – Tndstn
    Commented Aug 29 at 7:39

0

Browse other questions tagged or ask your own question.