コード例 #1
0
  private void setCaseSpinnerDatas(List<Case> cases) {
    mCaseSpinnerData.clear();
    for (Case aCase : cases) {
      mCaseSpinnerData.add(aCase);
    }

    mCaseSpinnerAdapter.notifyDataSetChanged();
  }
コード例 #2
0
  private void initCaseSpinner() {
    mCaseSpinnerAdapter =
        new CaseSpinnerAdapter(mContext, R.layout.icon_spinner_item, mCaseSpinnerData);
    mCaseSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
    mCaseSpinner.setAdapter(mCaseSpinnerAdapter);
    mCaseSpinner.setOnItemSelectedListener(
        new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Avoid the first call of onItemSelected() when the spinner is initialized.
            if (!mIsCaseSpinnerInitialized) {
              mIsCaseSpinnerInitialized = true;
              return;
            }

            changeCase(mCaseSpinnerData.get(position));
          }

          @Override
          public void onNothingSelected(AdapterView<?> parent) {}
        });
  }