コード例 #1
0
  @SuppressWarnings("unchecked")
  public IAnswerData getAnswer() {
    Vector<Selection> ve = new Vector<Selection>();
    Enumeration en = mItems.keys();
    String k = null;
    String v = null;

    // counter for offset
    int i = 0;
    while (en.hasMoreElements()) {
      k = (String) en.nextElement();
      v = (String) mItems.get(k);
      CheckBox c = ((CheckBox) findViewById(CHECKBOX_ID + i));
      if (c.isChecked()) {
        ve.add(new Selection(v));
      }
      i++;
    }

    if (ve.size() == 0) {
      return null;
    } else {
      return new SelectMultiData(ve);
    }
  }
コード例 #2
0
  public void clearAnswer() {
    int j = mItems.size();
    for (int i = 0; i < j; i++) {

      // no checkbox group so find by id + offset
      CheckBox c = ((CheckBox) findViewById(CHECKBOX_ID + i));
      if (c.isChecked()) {
        c.setChecked(false);
      }
    }
  }
コード例 #3
0
  @SuppressWarnings("unchecked")
  public void buildView(final PromptElement prompt) {
    mItems = prompt.getSelectItems();

    setOrientation(LinearLayout.VERTICAL);

    Vector ve = new Vector();
    if (prompt.getAnswerValue() != null) {
      ve = (Vector) prompt.getAnswerObject();
    }

    if (prompt.getSelectItems() != null) {
      OrderedHashtable h = prompt.getSelectItems();
      Enumeration en = h.keys();
      String k = null;
      String v = null;

      // counter for offset
      int i = 0;

      while (en.hasMoreElements()) {

        k = (String) en.nextElement();
        v = (String) h.get(k);

        // no checkbox group so id by answer + offset
        CheckBox c = new CheckBox(getContext());

        // when clicked, check for readonly before toggling
        c.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!mCheckboxInit && prompt.isReadonly()) {
                  if (buttonView.isChecked()) {
                    buttonView.setChecked(false);
                  } else {
                    buttonView.setChecked(true);
                  }
                }
              }
            });

        c.setId(CHECKBOX_ID + i);
        c.setText(k);
        c.setTextSize(TypedValue.COMPLEX_UNIT_PT, GlobalConstants.APPLICATION_FONTSIZE);

        for (int vi = 0; vi < ve.size(); vi++) {
          // match based on value, not key
          if (v.equals(((Selection) ve.elementAt(vi)).getValue())) {
            c.setChecked(true);
            break;
          }
        }

        c.setFocusable(!prompt.isReadonly());
        c.setEnabled(!prompt.isReadonly());
        addView(c);
        i++;
      }
    }

    mCheckboxInit = false;
  }