setContentView & listeners

Put your problem here if it does not fit any of the other categories.

setContentView & listeners

Postby sommeralex » Wed Jan 23, 2008 4:04 pm

why do i loose all my listeners, when i re-set the contentview??!!!

e.g:

setContentView(R.layout.main);

do some actions here.. like a button + its listener

button-listener works

method is called again:
setContentView(R.layout.main);

button-listener does not work anymore.
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Postby plusminus » Wed Jan 23, 2008 4:46 pm

Hello sommeralex,

because everytime you call setContentView the Views from main.xml get Inflated again :!:
Checking Javadoc:
public void setContentView(int layoutResID)
Set the activity content from a layout resource. The resource will be inflated, adding all top-level views to the activity.
Parameters
layoutResID Resource ID to be inflated.

I just made a picture showing the issue of inflating (My first try on inkscape ;) ):

[align=center]Image[/align]

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby sommeralex » Wed Jan 23, 2008 4:57 pm

thanks!!! :)

is there also the api in the "java api style" (3 frames?) - i could only find the help-document and i dont like it to work with...
sommeralex
Experienced Developer
Experienced Developer
 
Posts: 95
Joined: Sun Jan 20, 2008 3:12 am
Location: Vienna

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 18 guests