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