I am trying to work from the ActionbarSherlock example for adding a list navigation. In the example, there is some code like this:
@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);
}
and that seems to be it. So I am confused where I can add the titles for the navigation. And also it references
ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(
context, R.array.locations, R.layout.sherlock_spinner_item);
and my code is not aware of R.array.locations and gives a syntax error. But that R.array.locations is not in the examples. Should I create a separate file for it in my layout directory?
Thank you!
Regarding your compile error: Did you create an array resource called "locations"?
/res/values/arrays
<resources>
<string-array name="locations">
<item>Foo</item>
<item>Bar</item>
<item>Baz</item>
</string-array>
</resources>
Regarding providing special "tiles" for the dropdown: Even though it's called "List Navigation", what you are actually seeing in the Action Bar (both the native one and ActionBarSherlock's) is a Spinner. So you can give it any SpinnerAdapter and it will use that.
If you aren't familiar with adapters, I highly recommend you watch this video. The only difference between an adapter for a ListView and an adapter for a Spinner is the getDropDownView() method, which creates the views that appear in the dropdown menu (where getView() provides the view shown in the spinner content area).