Android - Change components of a Dialog

Asked

Viewed 25 times

0

I used a Dialog to display a custom alert this way:

Dialog dialog = new Dialog();
dialog.setContextView(R.layout.resource);
dialog.setTitle("Diálogo");
dialog.show();

However I can’t change Dialog xml elements using this Activity.

1 answer

0


First create an element in the Java class and then retrieve it from the Dialog. For example:

public void dialogClick() {

   Dialog dialog = new Dialog();
   dialog.setContextView(R.layout.resource);
   dialog.setTitle("Diálogo");
   dialog.show();

   View = dialog.findViewById(R.id.sua_view);
   view.setOnClickListener(ASuaListener());

}

Browser other questions tagged

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