0

currently i am designing an application in which i have a list and alphabetic scrollbar for the list. To load the data in list, i am calling a method in onCreate and also calling one method to build the alphabetic scrollbar for the list. now my problem is that when i am changing the orientation , the onCreate method is calling again due to which both inside methods are also calling again. but i dont want to call the method that is loading the data into list again . means the method which is loading data should not be called again when changing orientation while the method which is building the scrollbar should be called again.

plz tell me how i can do that.

thanks in advance

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
Sachin Kadian
  • 201
  • 3
  • 12
  • i think this will help you http://stackoverflow.com/questions/7139488/androidconfigchanges-orientation-does-not-work-with-fragments – Charan Pai Feb 19 '13 at 07:38
  • If you dont want to call methode which populates data to list then how u r going to populate data when orientation changed ? – Pankaj Feb 19 '13 at 08:10

3 Answers3

4

You can add this:

android:configChanges="orientation"

in the Manifest for required Activity tag

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    //reload your ScrollBars by checking the newConfig
}
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • i know this but if i will do this then the method which is building the scrollbar will also not reload during orientation change but i want this to reload. – Sachin Kadian Feb 19 '13 at 07:37
2

It happens because android assumes that a new activity has been created.

Use android :configChanges="orientation" in the activity part inside the android manifest

and dont forget to override this method :

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);    
}

This method will then be called on orientation change.Do the stuff you want to do in this code.

Payal
  • 903
  • 1
  • 9
  • 28
0

you can add android:configChanges="orientation" in your manifest of activity and manually set the contentView or change the layout by overriding OnConfigurationChanged

Manish Kumar
  • 1,062
  • 8
  • 19