Created an AlertDialog in which the .setView method adds a layout with EditText and buttons:

AlertDialog.Builder builder = new AlertDialog.Builder(HomeActivity.this); View view = HomeActivity.this.getLayoutInflater().inflate(R.layout.text_fields, null); 

In the same layout on one of the buttons I hang up an event that should take the value of EditText .
Button code:

  LayoutInflater factory = LayoutInflater.from(HomeActivity.this); View view = factory.inflate(R.layout.text_fields, null); EditText text = (EditText)view.findViewById(R.id.editText); System.out.println("Text of view: " + text.getText()); 

Displays either the default EditText value, if it is set, or empty, even though the EditText itself is filled.
Also if you register

  text.setText("some text"); 

it displays some text.

Why when you click on the button does not display the value of EditText ?

upd
If you do this manipulation, but without Inflate and setting setViewContent(R.layout.text_fields) , then everything is displayed. That is, I suppose the problem is that the ID EditText created in AlertDialog.Builder is missing.

    2 answers 2

    I think you have where

    Button code:

    no button code. There is a text field. And I'm not sure that the System.out.println command is the right decision ... Show the handler code, please.

      I always do this:

       text.getText().toString() 
      • Yes, I did the same. The problem was that the text field is in another xml, in which buttons are written, on which a certain method is launched on the click. In general, I simply removed the buttons and did all the actions in the AlertDialog. - rsergievsky