改变方向后,ABS onNavigationItemSelected调用两次

时间:2014-02-19 06:06:58

标签: android android-actionbar actionbarsherlock

使用Actionbarsherlock显示listnavigation。当方向改变了onNavigationItemSelected方法时,调用两次。让我知道这是什么问题。下面是我的示例代码。

    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;
    }
}

0 个答案:

没有答案