android - How to manage UI in java code? -


once set contentview layout, how can manage ui via java? also, if start new activity, reset contentview?

contentview in 1 activity.

assuming in extends activity have do, after setting content view, access views. have button in layout:

button homebutton = (button) findviewbyid(r.id.homebutton); homebutton.settext(); homebutton.setonclicklistener() etc 

if you're in dialog, or need access views in specific circumstances, or you're in intent , need access stuff in main activity's layout:

button secondbutton = (button) getactivity().findviewbyid(r.id.secondbutton); //other methods on button 

edits--

well images, add imageview layout:

<imageview android:id="@+id/logoimageview"         android:layout_width="wrap_content" android:layout_height="wrap_content"         android:src="@drawable/logo" android:contentdescription="@string/app_name"          android:layout_gravity="center_horizontal"/> 

you don't need code specifically, should show up.

buttons , other views can added via xml. can add things programmatically well, though it's not common.

if remember correctly, constructor create button in java that's not in xml file, button anewbutton = new button(getapplicationcontext()); anewbutton.settext("whatever");


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -