close alertdialog open with inflate

Asked

Viewed 298 times

0

I have a project with an open dialog box with an inflate giving the user the option to type a text to change the value of a String.

I’m having trouble closing this box and going back to the previous layout.

public class Calendario extends Activity {
    AlertDialog.Builder alert = new AlertDialog.Builder(Calendario.this);
    String Txt = "Digite sua mensagem";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.calendario );

Txtmessage = (TextView)  findViewById( R.id.EdtMensagemCalendar );
Txtmessage.setText( Txt );

Txtmessage.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            View v1 = getLayoutInflater().inflate(R.layout.edit, null);
            alert.setView(v1);
            alert.create();
            Edt = (EditText)  findViewById( R.id.EdtM );
            alert.show();


        }

    } );

the project loads the Edit layout inside the dialog box correctly, but need that after the user type the requested message that the dialog box close going back to the previous layout and providing new value to Edittext.

  • Thank you. I used an inflate because I wanted the dialog to have an editText, I solved the problem using a positivebutton "ok", it was what I needed to make it inflate and get the editText value. I don’t know why I couldn’t use Ismiss, it was a mistake. Thank you

  • In Edt you need to put -> Edittext Edt = (Edittext) v1.findViewById( R.id.Edtm ); because edt is in the inflated view v1, otherwise it will give nullpointer

1 answer

0

You can do the following: Open the dialog box, and when clicking the OK button of the dialog box pick the text entered, put it in such String and close the box.

Create a Listener for the dialog box and seven for the "OK button".

This listener can do it:

        String str = Edt.getText().toString(); //Pegar a String da caixa de diálogo
        alert.dismiss //fechar a caixa de diálogo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.