I have this neat app…
At onCreate, it draws the “startscreen.xml” accordingly to :
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.startscreen);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.window_title);
And in my app, i have “configChanges=”orientation” ” in the manifest.
And i have,
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.startscreen);
}
startscreen.xml is both a landscape and portrait-layout, both are separated.
So to the problem, the app loads fine, buttons work. I switch orientation, the button stops responding…
They are both using RelativeLayout…
Any clues, anyone? :S
EDIT:
Tried this now thanks to your comments, but no result :S
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.startscreen);
add_note.setOnClickListener(new View.OnClickListener() {
public void onClick(final View v) {
createNote();
}
});
}
Do you mean that onclickListener or these :
add_note = (Button) findViewById(R.id.addnote);
?? :S
If you are adding click listeners in
onCreateto your buttons, you need to add listeners to the new button objects created inonConfigurationChanged.You might consider using the
android:onClickattribute in your XML files instead of setting click listeners in code. That’s a nice way of avoiding this problem.To use
android:onClickfrom XML, do something like this:Then in your activity, define the method:
The name of the
android:onClickmethod is totally arbitrary; it just has to match a method in your activity with the proper signature (void <method_name>(View)). The method will be called when there’s a click in exactly the same manner that theonClickmethod would be called for anOnClickListener.When using
android:onClick, you do not need to callsetOnClickListener(or even retrieve a reference to the button inonCreate, unless you need it for something else).