0

Am using Actionbarsherlock to show the listnavigation. When the orientation changed the onNavigationItemSelected method called twice. Let me know what's the issue. below is my sample code.

    private TextView mSelected;
    private String[] mLocations;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setTheme(SampleList.THEME); //Used for theme switching in samples
        super.onCreate(savedInstanceState);

        setContentView(R.layout.list_navigation);
        mSelected = (TextView)findViewById(R.id.text);

        mLocations = getResources().getStringArray(R.array.locations);

        Context context = getSupportActionBar().getThemedContext();
        ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.locations, R.layout.sherlock_spinner_item);
        list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        getSupportActionBar().setListNavigationCallbacks(list, this);
        getSupportActionBar().setSelectedNavigationItem(1);

    }

    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        Log.d("ListNavigation", "selected");
        mSelected.setText("Selected: " + mLocations[itemPosition]);
        return true;
    }
}
Stefan
  • 5,203
  • 8
  • 27
  • 51
Dinesh T A
  • 2,087
  • 4
  • 26
  • 34
  • visit http://stackoverflow.com/questions/9517749/android-action-bar-onnavigationitemselected – Jitesh Upadhyay Feb 19 '14 at 06:08
  • @JiteshUpadhyay i handled the state but my problem is when i open the activity for the first time i added the same mentioned code but when the orientation changed the onNavigationItemSelected called twice. – Dinesh T A Feb 19 '14 at 06:12
  • please visit stack overflow question answerrs, i think it will solve yours issue http://stackoverflow.com/questions/10167162/onnavigationitemselected-in-actionbar-is-being-called-at-startup-how-can-avoid-i – Jitesh Upadhyay Feb 19 '14 at 06:31
  • @JiteshUpadhyay listen i have handled the startup validation like setting a boolean variable. my issue is onNavigationItemSelected called only one time from the activity startup but if i change the orientation it's being called double the time – Dinesh T A Feb 19 '14 at 06:37
  • yes i understand, please check with yours handling with all life cycle method and see the cause and investigate about it, check all the configurations, it willl help you, as i do not have exact code for that so i can not send a snippet to you!! – Jitesh Upadhyay Feb 19 '14 at 06:39
  • why you are not trying to have a flag at configuration change by means yours orientation change, maintain a flag for this purpose and work with configuration changes – Jitesh Upadhyay Feb 19 '14 at 06:41
  • @JiteshUpadhyay FYI - it's not called twice in below 4.0 – Dinesh T A Feb 21 '14 at 05:08
  • oh ok!! i will try to get solution and will be back to you if i will het the exact solution – Jitesh Upadhyay Feb 21 '14 at 05:10

0 Answers0