You can pass the text to the custom dialog as an argument by creating a constructor in your custom dialog class that takes a String parameter. Then, when you create an instance of the dialog in the different activity or class, you can pass the text as an argument to the constructor. Here is an example:
CustomDialog.java:
public class CustomDialog extends Dialog {
private String text;
public CustomDialog(Context context, String text) {
super(context);
this.text = text;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialog_layout);
TextView textView = findViewById(R.id.text_view);
textView.setText(text);
}
}
DifferentActivity.java:
public class DifferentActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_different);
String text = "Hello world!";
CustomDialog customDialog = new CustomDialog(this, text);
customDialog.show();
}
}
In this example, we create a new instance of the CustomDialog class in the DifferentActivity class and pass the String "Hello world!" as an argument to the constructor. The text is then set to a TextView in the custom dialog layout.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-18 20:05:56 +0000
Seen: 8 times
Last updated: Jul 18 '23
How can set the Project Title in the Doxygen Configuration File?
How can I convert Double to Long in Java?
Can I add a default Parameter for a Method in Java like int calculate(int x, int y=2)?
How can the rejection of the class text_plain from JavaMail API due to a VerifyError be confirmed?
Is it feasible to utilize a Toggle Button to switch among multiple classes exceeding 2?
How can I set up Environment variables on my M1 MacBook and resolve the ZSH permission denied error?
What is the process for generating a dynamic subdomain/URL using vue.js?