Good day. I'm just learning to program and can't find a working way to transfer text from EditText (which is in the dialog box) to the ListView :

 public class CustomDialofFragment extends DialogFragment { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); return builder.setTitle("имя") .setView(R.layout.dialog) .setPositiveButton("Далее", null) .setNegativeButton("Отмена", null) .create(); } } 
  • If you need to transfer the value from the dialog, then create a dialog method that will transfer the value from the EditText to your activation. Can I see the dialogue code? - Andriy Martsinkevych
  • Should the text be transmitted when clicking on the "Next" button? - Andriy Martsinkevych
  • Yes, I don’t see yet another option due to lack of experience - Alpancho

1 answer 1

Something like this should work:

 EditText editText; View view = getActivity().getLayoutInflater().inflate(R.layout.dialog, null); editText = (EditText) view.findViewById(R.id.MY_ID); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); return builder .setTitle("имя") .setView(view) .setPositiveButton("Далее", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { sendText(editText.getText().toString())) } }) .setNegativeButton("Отмена", null) .create(); 
  • Probably the implementation of the sendText() method is also worth adding, in nm, in general, the whole point of the interaction. - pavlofff
  • Fully agree .... - Alpancho