Android Spinner Dialog Is Not Populating?
I have an activity made up of two fragments. On the left is a sidebar, on the right is a MapView (See screenshot below). On the left I have a spinner that will be populated with o
Solution 1:
The problem is not the Spinner, the problem is that you are inflating two Spinners. One in on onCreateView method and the other in this line :
this.getActivity().setContentView(R.layout.sidefragment);
And only one the spinner with the provider... so I recommend you to set all your GUI variable at onCreationView like this:
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Viewv= inflater.inflate(R.layout.sidefragment, container, true);
finalSpinners= (Spinner) v.findViewById(
R.id.track_spinner);
ArrayAdapter<String> adapter = newArrayAdapter<String>(this
.getActivity().getBaseContext(),
android.R.layout.simple_spinner_item, tracks);
s.setAdapter(adapter);
s.setOnItemSelectedListener(newOnItemSelectedListener() {
@OverridepublicvoidonItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
intitem= s.getSelectedItemPosition();
Toast.makeText(SideFragment.this.getActivity().getBaseContext(),
"clicked "+item, Toast.LENGTH_SHORT).show();
}
@OverridepublicvoidonNothingSelected(AdapterView<?> arg0) {
}
});
return v;
}
And remove the overrided method onCreate.
Solution 2:
this is how I always have done my spinners
ArrayAdapter<CharSequence> cAdapter;
cAdapter = ArrayAdapter.createFromResource(this, R.array.colors,android.R.layout.simple_spinner_item);
int cSpinnerDD = android.R.layout.simple_spinner_dropdown_item;
cAdapter.setDropDownViewResource(cSpinnerDD);
color.setAdapter(cAdapter);
give that a try
Post a Comment for "Android Spinner Dialog Is Not Populating?"