Suppose my current activity is Main.java and I have already declared its layout through setContentView(R.layout.layout1) from its onCreate method. Now, is it in any way possible for me to access a different layout? For e.g., assuming there is another layout – layout2 which has TextView with id tv, then I won’t be able to execute the following code from Main.java :
TextView text = (TextView) findViewById(R.id.tv);
text.setText("blah blah");
Is there any way that I can set tv‘s value from Main.java.
My actual code is the following
setContentView(R.layout.layout);
Button button = (Button) findViewById(button);
button(buttonListener);
Dialog dialog;
Inside the listener, I have the following code:
TextView dialogTitle = (TextView) findViewById(R.id.dialog_title);
dialogTitle.setText("Email");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View customView = getLayoutInflater().inflate(R.layout.dialog, null);
builder.setView(customView);
dialog = builder.create();
dialog.show();
The problem that I am facing is that dialog_title is in dialog.xml and not in layout.xml
1 Answer