How to use the clipboard to copy and paste [closed]

-1

Using the android clipboard, to copy a text from a textView, I need to copy that text and use it to paste it somewhere else.

    
asked by anonymous 07.12.2016 / 12:34

2 answers

1

Use TextView with property android:textIsSelectable=true

<TextView
    android:id="@+id/text_to_copy"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textIsSelectable="true" />
    
07.12.2016 / 12:45
0

My solution:

final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(DetalhesDebitosActivity.this);
                                        //alertDialogBuilder.setMessage(result);

                                        final TextView input = new TextView(DetalhesDebitosActivity.this);
                                        alertDialogBuilder.setView(input);

                                        input.setText(result);

                                        input.setTextIsSelectable(true);


                                        input.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
                                        input.setTextSize(16);


        /*
                                        alertDialogBuilder.setNegativeButton("Ok",new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {


                                            }
                                        });*/


                                        alertDialogBuilder.setPositiveButton("Copiar",new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

                                                clipboard.setText(input.getText().toString());
                                                Toast.makeText(getApplicationContext(), "Linha digitável copiada!", Toast.LENGTH_SHORT).show();

                                                finish();


                                            }
                                        });



                                        AlertDialog alertDialog = alertDialogBuilder.create();
                                        alertDialog.show();
    
07.12.2016 / 15:44