You’ve got it screwed up, it’s impossible to understand what goal you’re trying to achieve, for the builder, the setView method is called twice, and the setContentView is called by the activation class. As for editText, then it would be best to edit the text inside the dialog_newblock.xml, assign it an id (for example, edit_text) and do something like this
public class Dialogs extends MainActivity { public void newLanguageDialog(Context context , final View view){ View view = LayoutInflater.from(context).inflate(R.layout.dialog_newblock); EditText input = (EditText) view.findViewById(R.id.edit_text); final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setView(view); builder.setCancelable(false); builder.setTitle("111"); builder.setMessage("222"); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // do smth // dialog.cancel(); - не надо вызывать, вызовется само } }); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String a = input.getText().toString(); if (a.length() > 0) { MainActivity.s = a; //setContentView(R.layout.activity_main); // dialog.cancel(); } else { // setContentView(R.layout.main_one); // dialog.cancel(); } } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); } }
At what point is the dialogue called? And at what point is setContentView called? To be honest, it seems to me a strange idea to change the contents of an activation by pressing a button (I have never done this, not even sure that it will work), it is better to make an activation container and change fragments inside it
And on your question it is not entirely clear what you are trying to achieve.
UPDATED:
Created a project and tried it - it worked)) Very nice. However, I will try to convince you - this is a bad practice, handling several markup in one activity. The project has a tendency to grow, and for each markup you will have to combine the view binding into a separate logic, which will be within the same class (your activity). In a toga, it will grow into many hundreds and thousands of few manageable lines of code. It is more correct to do several activations, or one activit with a container (FrameLayout, for example) where to add different fragments, into which the logic of each individual page will be iasked. And there is nothing terrible, because you will have several classes, not just one. And what's more, if you go further, the presentation logic is generally better to separate from the business of logic, but you will find out later when you get acquainted with the architectural patterns or such a wonderful thing as Android Data Binding.