In my Android application, I am using spinner, and I have loaded data from the SQLite database into the spinner, and it\'s working properly. Here is the code for that.
Another variation of Ashraf's solution would be to make sure you're taking into account screen sizes. You'll need to get the spinner in onCreate and set the listener after you set the adapter:
//set your adapter with default or custom spinner cell, then://
serverSpinner.setOnItemSelectedListener(spinnerSelector);
serverSpinner.setSelection(defaultServer);
Then you can start changing the text size of the view that's showing before the spinner is clicked:
private AdapterView.OnItemSelectedListener spinnerSelector = new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView> parent, View view, int pos, long id) {
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
boolean largeTablet = getResources().getBoolean(R.bool.isLargeTablet);
if (tabletSize) { ((TextView)parent.getChildAt(0)).setTextSize(16); }
else if (largeTablet) { ((TextView)parent.getChildAt(0)).setTextSize(18); }
else { ((TextView)parent.getChildAt(0)).setTextSize(12); }
}
public void onNothingSelected(AdapterView> parent) {
}
};
All you need to do is create layout specific folders like this:
values-sw360dp
values-sw600dp
values-sw800dp
an then add an xml file named "bool.xml" into each of those folders:
false
false