use of com.instructure.teacher.adapters.NothingSelectedSpinnerAdapter in project instructure-android by instructure.
the class AddMessageFragment method addCoursesAndGroups.
@Override
public void addCoursesAndGroups(ArrayList<Course> courses, ArrayList<Group> groups) {
final CanvasContextSpinnerAdapter adapter = CanvasContextSpinnerAdapter.newAdapterInstance(getContext(), courses, groups);
mCourseSpinner.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.spinner_item_nothing_selected, getContext()));
if (mSelectedCourse != null) {
// prevent listener from firing the when selection is placed
mCourseSpinner.setOnItemSelectedListener(null);
// + 1 is for the nothingSelected position
mCourseSpinner.setSelection(adapter.getPosition(mSelectedCourse) + 1, false);
courseWasSelected();
}
mCourseSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (position != 0) {
// position zero is nothingSelected prompt
// -1 to account for nothingSelected item
CanvasContext canvasContext = adapter.getItem(position - 1);
if (mSelectedCourse == null || mSelectedCourse.getId() != canvasContext.getId()) {
mChipsTextView.removeAllRecipientEntry();
mSelectedCourse = canvasContext;
courseWasSelected();
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
Aggregations