示例#1
0
 @Override
 public View getView(Context context) {
   s = new SwitchCompat(context);
   s.setText(varName);
   s.setChecked(loadVar());
   s.setPadding(DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING, DEFAULT_PADDING);
   return s;
 }
  private void initData(DipReceiver receiver) {
    LinkedList<DipSwitch> dips = receiver.getDips();

    int i;
    for (i = 0; i < receiver.getDipNames().size(); i++) {
      SwitchCompat currentSwitch = dipViewList.get(i);
      currentSwitch.setText(receiver.getDipNames().get(i));
      currentSwitch.setVisibility(View.VISIBLE);
      currentSwitch.setChecked(dips.get(i).isChecked());
    }
    while (i < 10) {
      SwitchCompat currentSwitch = dipViewList.get(i);
      currentSwitch.setVisibility(View.INVISIBLE);
      i++;
    }

    dipSwitchArrayList = new ArrayList<>();
    for (SwitchCompat switchCompat : dipViewList) {
      if (switchCompat.getVisibility() == View.VISIBLE) {
        dipSwitchArrayList.add(
            new DipSwitch(switchCompat.getText().toString(), switchCompat.isChecked()));
      }
    }
  }