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.
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.
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" />
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();