Once I set the contentView to a layout, how can I manage the UI via java? Also, if I start a new activity, do I reset the contentView?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ContentView will only be in one activity.
Assuming you are in something that extends
Activityall you have to do, after setting content view, is access your views. Say you have a button in your layout:If you’re in a dialog, or need to access certain views in specific circumstances, or you’re in an intent and need to access stuff in your main activity’s layout:
EDITS–
Well images, you just add an ImageView into the layout:
You don’t need to do anything with code specifically, it should just show up.
Buttons and other views can also be added via XML. You can add things programmatically as well, though it’s not as common.
If I remember correctly, the constructor to create a button in Java that’s not in your XML file, it would be
Button aNewButton = new Button(getApplicationContext());aNewButton.setText("whatever");