Fixed bug where list selection would be lost after rotation (again)

pull/14/head
Sam Bosley 13 years ago
parent 2a8134947c
commit 7cc611b50d

@ -86,8 +86,7 @@ public class AstridWrapperActivity extends FragmentActivity
*/
public boolean onFilterItemClicked(FilterListItem item) {
if (this instanceof TaskListWrapperActivity) {
int selectedPosition = ((TaskListWrapperActivity) this).getFilterItemPosition(item);
getSupportActionBar().setSelectedNavigationItem(selectedPosition);
((TaskListWrapperActivity) this).setSelectedItem(item);
}
if (!mMultipleFragments || (item instanceof SearchFilter)) {
if(item instanceof Filter) {

@ -13,6 +13,9 @@ import com.todoroo.astrid.service.ThemeService;
public class TaskListWrapperActivity extends AstridWrapperActivity {
public static final String TOKEN_SELECTED_FILTER = "selectedFilter";
private int selectionToSet;
private ArrayAdapter<FilterListItem> listDropdownAdapter;
/**
* @see android.app.Activity#onCreate(Bundle)
@ -30,6 +33,11 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
if (savedInstanceState != null) {
selectionToSet = savedInstanceState.getInt(TOKEN_SELECTED_FILTER);
}
}
/* (non-Javadoc)
@ -57,10 +65,21 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
return true;
}
});
if (selectionToSet != -1 && selectionToSet < listDropdownAdapter.getCount()) {
selectionToSet = -1;
getSupportActionBar().setSelectedNavigationItem(selectionToSet);
}
}
@Override
protected void onSaveInstanceState(Bundle icicle) {
icicle.putInt(TOKEN_SELECTED_FILTER, getSupportActionBar().getSelectedNavigationIndex());
super.onSaveInstanceState(icicle);
}
public int getFilterItemPosition(FilterListItem item) {
return listDropdownAdapter.getPosition(item);
public void setSelectedItem(FilterListItem item) {
int position = listDropdownAdapter.getPosition(item);
getSupportActionBar().setSelectedNavigationItem(position);
}
@Override

Loading…
Cancel
Save