I’m using SherlockActionbar and I wanted to fill dynamically the ListNavigation spinner in the actionbar. The problem is that my list navigation doesn’t display anything. However the app is running on the emulator without any errors.
Here is the activity code:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
public class TestView extends SherlockFragmentActivity {
private ArrayAdapter<String> listnav;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.test_view_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ActionBar ab = getSupportActionBar();
ab.setDisplayShowTitleEnabled(false);
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
Context context = ab.getThemedContext();
setContentView(R.layout.test_view);
List<String> items = new ArrayList<String>(Arrays.asList(getResources().getStringArray(R.array.testarray)));
listnav = new ArrayAdapter<String>(context, R.layout.sherlock_spinner_item, items);
listnav.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
}
}
Here is the code for the array resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="testarray">
<item >2011</item>
<item >2012</item>
</string-array>
</resources>
I solved this problem. The spinner in the actionbar can be accessed with the setListNavigationCallbacks.
For more Information about this method click here
I solved this problem. The spinner in the actionbar can be accessed with the setListNavigationCallbacks. For more Information about this method click here