Advertisement
Sketchware

Para criar uma caixa de diálogo que permita ao usuário digitar um texto e exibir o texto no "EditTex

Jan 9th, 2023
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.79 KB | None | 0 0
  1. Button button = (Button) findViewById(R.id.button);
  2. final EditText editText = (EditText) findViewById(R.id.edit_text);
  3. button.setOnClickListener(new View.OnClickListener() {
  4.     @Override
  5.     public void onClick(View v) {
  6.         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  7.         builder.setTitle("Digite o texto");
  8.         final EditText input = new EditText(MainActivity.this);
  9.         builder.setView(input);
  10.         builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
  11.             @Override
  12.             public void onClick(DialogInterface dialog, int which) {
  13.                 editText.setText(input.getText().toString());
  14.             }
  15.         });
  16.         builder.setNegativeButton("Cancelar", null);
  17.         builder.show();
  18.     }
  19. });
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement