android.widget.CheckBox.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中android.widget.CheckBox.<init>()方法的一些代码示例,展示了CheckBox.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CheckBox.<init>()方法的具体详情如下:
包路径:android.widget.CheckBox
类名称:CheckBox
方法名:<init>

CheckBox.<init>介绍

暂无

代码示例

代码示例来源:origin: gzu-liyujiang/AndroidPicker

@NonNull
@Override
protected ScrollView makeCenterView() {
  ScrollView scrollView = new ScrollView(activity);
  layout = new LinearLayout(activity);
  layout.setOrientation(LinearLayout.VERTICAL);
  for (String item : items) {
    LinearLayout line = new LinearLayout(activity);
    line.setOrientation(LinearLayout.HORIZONTAL);
    line.setGravity(Gravity.CENTER);
    TextView textView = new TextView(activity);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, WRAP_CONTENT, 1.0f);
    lp.gravity = Gravity.CENTER;
    textView.setLayoutParams(lp);
    textView.setText(item);
    textView.setGravity(Gravity.CENTER);
    line.addView(textView);
    CheckBox checkBox = new CheckBox(activity);
    checkBox.setLayoutParams(new LinearLayout.LayoutParams(0, WRAP_CONTENT, 0.4f));
    line.addView(checkBox);
    layout.addView(line);
  }
  scrollView.addView(layout);
  return scrollView;
}

代码示例来源:origin: googlemaps/android-maps-utils

/**
 * Creates check box for a given search term
 *
 * @param keyword the search terms associated with the check box
 */
private void makeCheckBox(final String keyword) {
  mCheckboxLayout.setVisibility(View.VISIBLE);
  // Make new checkbox
  CheckBox checkBox = new CheckBox(this);
  checkBox.setText(keyword);
  checkBox.setTextColor(HEATMAP_COLORS[mOverlaysRendered]);
  checkBox.setChecked(true);
  checkBox.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      CheckBox c = (CheckBox) view;
      // Text is the keyword
      TileOverlay overlay = mOverlays.get(keyword);
      if (overlay != null) {
        overlay.setVisible(c.isChecked());
      }
    }
  });
  mCheckboxLayout.addView(checkBox);
}

代码示例来源:origin: lygttpod/SuperTextView

/**
 * 初始化RightCheckBox
 */
private void initRightCheckBox() {
  if (rightCheckBox == null) {
    rightCheckBox = new CheckBox(mContext);
  }
  rightCheckBoxParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  rightCheckBoxParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
  rightCheckBoxParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
  rightCheckBoxParams.setMargins(0, 0, rightCheckBoxMarginRight, 0);
  rightCheckBox.setId(R.id.sRightCheckBoxId);
  rightCheckBox.setLayoutParams(rightCheckBoxParams);
  if (rightCheckBoxBg != null) {
    rightCheckBox.setGravity(CENTER_IN_PARENT);
    rightCheckBox.setButtonDrawable(rightCheckBoxBg);
  }
  rightCheckBox.setChecked(isChecked);
  rightCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      if (checkBoxCheckedChangeListener != null) {
        checkBoxCheckedChangeListener.onCheckedChanged(buttonView, isChecked);
      }
    }
  });
  addView(rightCheckBox);
}

代码示例来源:origin: robolectric/robolectric

@Test
 public void testWorks() throws Exception {
  CheckBox checkBox = new CheckBox(ApplicationProvider.getApplicationContext());
  assertThat(checkBox.isChecked()).isFalse();

  checkBox.setChecked(true);
  assertThat(checkBox.isChecked()).isTrue();

  checkBox.toggle();
  assertThat(checkBox.isChecked()).isFalse();

  checkBox.performClick();  // Used to support performClick(), but Android doesn't. Sigh.
//        assertThat(checkBox.isChecked()).isFalse();
 }
}

代码示例来源:origin: smuyyh/BookReader

private void initView() {
  removeAllViews();
  for (int i = 0; i < countNum; i++) {
    CheckBox cb = new CheckBox(getContext());
    LayoutParams layoutParams;
    if (widthAndHeight == 0) {

代码示例来源:origin: renyuneyun/Easer

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  LinearLayout linearLayout = new LinearLayout(getContext());
  linearLayout.setOrientation(LinearLayout.VERTICAL);
  for (int i = 0; i < checkBoxes.length; i++) {
    checkBoxes[i] = new CheckBox(getContext());
    checkBoxes[i].setText(mode_names[i]);
    linearLayout.addView(checkBoxes[i]);
  }
  return linearLayout;
}

代码示例来源:origin: lltvcn/FreeText

private void addView(String str) {
  CheckBox tv = new CheckBox(viewContainer.getContext());
  tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  tv.setText(str);
  viewContainer.addView(tv);
  if(obj!=null&&obj.equals(getString(str))){
    tv.setChecked(true);
  }
  tv.setOnCheckedChangeListener(lis);
}

代码示例来源:origin: renyuneyun/Easer

@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  LinearLayout linearLayout = new LinearLayout(getContext());
  linearLayout.setOrientation(LinearLayout.VERTICAL);
  for (int i = 0; i < checkBoxes.length; i++) {
    checkBoxes[i] = new CheckBox(getContext());
    checkBoxes[i].setText(mode_names[i]);
    linearLayout.addView(checkBoxes[i]);
  }
  return linearLayout;
}

代码示例来源:origin: szugyi/Android-CircleMenu

private void showIsRotatingDialog() {
  CheckBox isRotatingCheck = new CheckBox(this);
  isRotatingCheck.setText(R.string.is_rotating);
  isRotatingCheck.setChecked(circleLayout.isRotating());
  isRotatingCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      circleLayout.setRotating(isChecked);
    }
  });
  new AlertDialog.Builder(this)
      .setTitle(R.string.dialog_is_rotating)
      .setView(isRotatingCheck)
      .setPositiveButton(android.R.string.ok, null)
      .create().show();
}

代码示例来源:origin: Chion82/WeChatMomentStat-Android

protected void loadUserList() {
  LinearLayout userListContainer = (LinearLayout)findViewById(R.id.user_list_container);
  ArrayList<UserSnsInfo> userSnsList = Share.snsData.userSnsList;
  checkBoxList.clear();
  userListContainer.removeAllViews();
  for (int i=0;i<userSnsList.size();i++) {
    CheckBox userCheckBox = new CheckBox(this);
    userCheckBox.setText(userSnsList.get(i).userName + "(" + userSnsList.get(i).userId + ")" + "(" + String.format(getString(R.string.user_moment_count), userSnsList.get(i).snsList.size()) + ")");
    userListContainer.addView(userCheckBox);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)userCheckBox.getLayoutParams();
    layoutParams.setMargins(5, 5, 5, 5);
    userCheckBox.setLayoutParams(layoutParams);
    userCheckBox.setChecked(true);
    userCheckBox.setTag(userSnsList.get(i).userId);
    checkBoxList.add(userCheckBox);
  }
}

代码示例来源:origin: devunwired/custom-touch-examples

private void init() {
  mButton = new CheckBox(getContext());
  mButton.setText("Click Anywhere On Screen");
  
  addView(mButton, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
}

代码示例来源:origin: Wilm0r/giggity

public ImportSelections(Context ctx_, Schedule mine_, Schedule.Selections other_) {
  super(ctx_);
  ctx = ctx_;
  mine = mine_;
  other = other_;
  
  setTitle(R.string.import_selections);
  setCanceledOnTouchOutside(false);
  
  opts = new LinearLayout(ctx);
  opts.setOrientation(LinearLayout.VERTICAL);
  
  cbs = new CheckBox[4];
  int i;
  String[] choices = ctx.getResources().getStringArray(R.array.import_selections_options);
  for (i = 0; i < 4; i ++) {
    cbs[i] = new CheckBox(ctx);
    cbs[i].setChecked(i != IMPORT_HIDDEN);
    cbs[i].setText(choices[i]);
    opts.addView(cbs[i]);
  }
  
  Button ok = new Button(ctx);
  ok.setText(R.string.ok);
  ok.setOnClickListener(this);
  opts.addView(ok);
  
  setContentView(opts);
}

代码示例来源:origin: HelloChenJinJun/TestChat

public BaseDialog setCheckBoxName(List<String> list) {
    if (middleLayout.getChildCount() > 0) {
        middleLayout.removeAllViews();
    }
    for (String title :
        list) {
        TextView textView = new TextView(getContext());
        textView.setGravity(Gravity.START);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.weight = 1;
        textView.setLayoutParams(layoutParams);
        textView.setText(title);
        final CheckBox checkBox = new CheckBox(getContext());
        checkBox.setGravity(Gravity.END);
        LinearLayout.LayoutParams checkBoxLayout = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        checkBoxLayout.weight = 1;
        checkBox.setLayoutParams(checkBoxLayout);
        LinearLayout linearLayout = new LinearLayout(getContext());
        LinearLayout.LayoutParams linearLayoutParam = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        linearLayout.setGravity(Gravity.CENTER_VERTICAL);
        linearLayout.setWeightSum(2);
        linearLayout.setLayoutParams(linearLayoutParam);
        linearLayout.addView(textView);
        linearLayout.addView(checkBox);
        middleLayout.addView(linearLayout);
    }
    return this;
}

代码示例来源:origin: geniusgithub/AndroidDialer

/**
 * Returns the {@link CheckBox} view, creating it if necessary.
 */
public CheckBox getCheckBox() {
  if (mCheckBox == null) {
    mCheckBox = new CheckBox(getContext());
    // Make non-focusable, so the rest of the ContactListItemView can be clicked.
    mCheckBox.setFocusable(false);
    addView(mCheckBox);
  }
  return mCheckBox;
}

代码示例来源:origin: dkharrat/NexusDialog

@Override
protected View createFieldView() {
  LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  ViewGroup checkboxContainer = (ViewGroup) inflater.inflate(R.layout.form_checkbox_container, null);
  CheckBox checkBox;
  int nbItem = items.size();
  for (int index = 0; index < nbItem; index++) {
    checkBox = new CheckBox(getContext());
    checkBox.setText(items.get(index));
    checkBox.setId(CHECKBOX_ID + index);
    checkBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        int position = buttonView.getId() - CHECKBOX_ID;
        Object value = areValuesDefined() ? values.get(position): position;
        Set<Object> modelValues = new HashSet<>(retrieveModelValues());
        if (isChecked) {
          modelValues.add(value);
        } else {
          modelValues.remove(value);
        }
        getModel().setValue(getName(), modelValues);
      }
    });
    checkboxContainer.addView(checkBox);
    refresh(checkBox, index);
  }
  return checkboxContainer;
}

代码示例来源:origin: line/line-sdk-android

private void buildScopeCheckBoxes() {
  final List<Scope> scopes = (BuildConfig.INCLUDE_INTERNAL_API_TEST)?
    Arrays.asList(Scope.PROFILE,
        Scope.FRIEND,
        Scope.GROUP,
        Scope.MESSAGE,
        Scope.OPENID_CONNECT,
        Scope.OC_EMAIL,
        Scope.OC_PHONE_NUMBER,
        Scope.OC_GENDER,
        Scope.OC_BIRTHDATE,
        Scope.OC_ADDRESS,
        Scope.OC_REAL_NAME)
  :
    Arrays.asList(Scope.PROFILE, Scope.OPENID_CONNECT);
  final FragmentActivity activity = getActivity();
  for (final Scope scope : scopes) {
    final CheckBox checkBox = new CheckBox(activity);
    checkBox.setText(scope.getCode());
    checkBox.setTag(scope);
    scopeCheckboxLayout.addView(checkBox);
    scopeCheckBoxes.add(checkBox);
  }
}

代码示例来源:origin: marzika/Snapprefs

/**
   * Opens SnapChat's Resources and gets the pretty checkbox, for reuse & consistent appearance
   *
   * @param c SNAPCHAT's context
   * @return A pretty checkbox (hopefully)
   */
  public static CheckBox getCheckbox(Context c) {
    CheckBox cb = new CheckBox(c);
    try {
      //Setting properties from Snapchat's res/layout/send_to_item.xml checkbox
      cb.setButtonDrawable(c.getResources().getIdentifier("send_to_button_selector", "drawable", "com.snapchat.android"));
      //May need to scale drawable bitmap...
      cb.setScaleX(0.7F);
      cb.setScaleY(0.7F);
    } catch (Exception e) {
      Logger.log("Snapprefs: Error getting Checkbox");
    }
    return cb;
  }
}

代码示例来源:origin: llollox/CompoundButtonGroup

private void prepareButton() {
  switch (viewType) {
    case CHECK_BOX:     this.button = new CheckBox(context); break;
    case RADIO:         this.button = new RadioButton(context); break;
    default:            throw new RuntimeException("Unknown View Type");
  }
  button.setLayoutParams(new ViewGroup.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      ViewGroup.LayoutParams.WRAP_CONTENT));
  button.setClickable(false);
  setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      if (listener != null) {
        listener.onButtonClicked(v);
      }
      button.setChecked(!button.isChecked());
    }
  });
}

代码示例来源:origin: dsolonenko/financisto

@Override
protected void internalOnCreate() {
  fieldSeparators = (Spinner)findViewById(R.id.spinnerFieldSeparator);
  includeHeader = (CheckBox)findViewById(R.id.checkboxIncludeHeader);
  exportSplits = new CheckBox(this); //(CheckBox)findViewById(R.id.checkboxExportSplits);
  includeHeader = (CheckBox)findViewById(R.id.checkboxIncludeHeader);
  uploadToDropbox = (CheckBox)findViewById(R.id.checkboxUploadToDropbox);
}

代码示例来源:origin: termux/termux-api

@Override
LinearLayout createWidgetView(AppCompatActivity activity) {
  LinearLayout layout = new LinearLayout(activity);
  layout.setOrientation(LinearLayout.VERTICAL);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  layoutParams.topMargin = 32;
  layoutParams.bottomMargin = 32;
  String[] values = getInputValues(activity.getIntent());
  for (int j = 0; j < values.length; ++j) {
    String value = values[j];
    CheckBox checkBox = new CheckBox(activity);
    checkBox.setText(value);
    checkBox.setId(j);
    checkBox.setTextSize(18);
    checkBox.setPadding(16, 16, 16, 16);
    checkBox.setLayoutParams(layoutParams);
    layout.addView(checkBox);
  }
  return layout;
}

相关文章