Android CheckBox - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android CheckBox class.

This code example shows how to use the following methods:isChecked
		assertEquals( null, androidWidgetBuilder.getValue( new View( null ) ) );
		assertFalse( androidWidgetBuilder.setValue( null, null ) );
 
		// CheckBox 
 
		CheckBox checkBox = new CheckBox( null );
		assertTrue( false == (Boolean) androidWidgetBuilder.getValue( checkBox ) );
		androidWidgetBuilder.setValue( true, checkBox );
		assertTrue( checkBox.isChecked() );
		assertTrue( true == (Boolean) androidWidgetBuilder.getValue( checkBox ) );
 
		// TextView 
 
		TextView textView = new TextView( null );
		assertEquals( null, androidWidgetBuilder.getValue( textView ) );
		androidWidgetBuilder.setValue( "foo", textView );
		assertEquals( "foo", textView.getText() );
		assertEquals( "foo", androidWidgetBuilder.getValue( textView ) );
 
		textView.setText( new SpannableStringBuilder( "foo" ) );
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setId, setLayoutParams, setChecked, setOnCheckedChangeListener
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		checkboxparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		checkboxparams.addRule(RelativeLayout.CENTER_VERTICAL);
 
		checkbox = new CheckBox(getContext());
		checkbox.setLayoutParams(checkboxparams);
		checkbox.setOnCheckedChangeListener(this);
		checkbox.setId(CHECKBOX_ID);
		 
		 
 
		layout.addView(title);
		layout.addView(description);
		layout.addView(checkbox);
		layout.setId(android.R.id.widget_frame);
 
		checkService(); 
		 
		return layout;

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isChecked, setChecked
    public FileItemInfoLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    } 
 
    public void toggle() { 
        setChecked(!mCheckbox.isChecked());
    } 
 
    /* (non-Javadoc) 
     * @see android.view.View#onFinishInflate() 
     */ 
    @Override 
    protected void onFinishInflate() { 
        super.onFinishInflate(); 
        mFileNameView = (TextView) findViewById(R.id.misc_filename);
        mFileSizeView = (TextView) findViewById(R.id.misc_filesize);
        mCheckbox = (CheckBox) findViewById(R.id.misc_checkbox);
    } 
 
    public void setFileName(String fileName) {

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isChecked
 
	@Override 
	public void onAccept() { 
		super.onAccept(); 
		AccountManager.getInstance().setPassword(account,
				storePasswordView.isChecked(),
				passwordView.getText().toString());
		finish(); 
	} 
 
	@Override 
	public void onDecline() { 
		AccountManager.getInstance().removePasswordRequest(account);
		finish(); 
	} 
 
	public static Intent createIntent(Context context, String account) {
		return new AccountIntentBuilder(context, PasswordRequest.class)
				.setAccount(account).build();
	} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setChecked
        mCheckBox = (CheckBox) findViewById(R.id.check);
    } 
 
    @Override 
    public void setChecked(boolean checked) {
        mCheckBox.setChecked(checked);
    } 
 
    @Override 
    public boolean isChecked() { 
        return mCheckBox.isChecked();
    } 
 
    @Override 
    public void toggle() { 
        mCheckBox.toggle();
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setOnClickListener, setChecked, setGravity, setPadding
 
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, 64);
 
            CheckBox checkBox = new CheckBox(Plugins_View.this);
            checkBox.setLayoutParams(lp);
            // Center the text vertically 
            checkBox.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER);
            // Set the text starting position 
            checkBox.setOnClickListener(new OnClickListener(){
            	public void onClick(View v){
                    if (((CheckBox) v).isChecked()) {
                    	SharedPreferences settings = getSharedPreferences("Munin_Node", 0);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putBoolean(((CheckBox) v).getText().toString(), true);
                        editor.commit();
                    } else { 
                    	SharedPreferences settings = getSharedPreferences("Munin_Node", 0);
                        SharedPreferences.Editor editor = settings.edit();

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setTag, setChecked, setOnCheckedChangeListener
    } 
 
    private void initItemCheckbox(int position, ViewGroup view) {
        CheckBox checkBox = (CheckBox) view.findViewById(android.R.id.checkbox);
        boolean selected = isSelected(position);
        checkBox.setTag(position);
        checkBox.setChecked(selected);
        checkBox.setOnCheckedChangeListener(this);
    } 
 
    @SuppressWarnings("deprecation") 
    private void updateItemBackground(int position, View v) {
        long handle = positionToSelectionHandle(position);
        boolean selected = isSelected(handle);
        Drawable bg = selected ? selectedItemBackground : unselectedItemBackground;
        v.setBackgroundDrawable(bg);
    } 
     
    @Override 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isChecked
		if (mAccountId <= 0) return;
		switch (which) {
			case DialogInterface.BUTTON_POSITIVE: {
				mName = ParseUtils.parseString(mEditName.getText());
				mDescription = ParseUtils.parseString(mEditDescription.getText());
				mIsPublic = mPublicCheckBox.isChecked();
				if (mName == null || mName.length() <= 0) return;
				mTwitterWrapper.createUserList(mAccountId, mName, mIsPublic, mDescription);
				break; 
			} 
		} 
 
	} 
 
	@Override 
	public Dialog onCreateDialog(final Bundle savedInstanceState) {
		mTwitterWrapper = getApplication().getTwitterWrapper();
		final Bundle bundle = savedInstanceState == null ? getArguments() : savedInstanceState;
		mAccountId = bundle != null ? bundle.getLong(INTENT_KEY_ACCOUNT_ID, -1) : -1;
		final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setOnCheckedChangeListener, setSelected
        p = new AbsoluteLayout.LayoutParams(IP_WIDTH, AbsoluteLayout.LayoutParams.WRAP_CONTENT, 320
                - IP_WIDTH - INSETS, INSETS - 10);
        edtIpAddress.setLayoutParams(p);
        layout.addView(edtIpAddress);
 
        cbxAccelerometer = new CheckBox(this);
        cbxAccelerometer.setSelected(false);
        p = new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
                AbsoluteLayout.LayoutParams.WRAP_CONTENT, 320 - IP_WIDTH - INSETS, 3 * INSETS - 10);
        cbxAccelerometer.setLayoutParams(p);
        cbxAccelerometer.setOnCheckedChangeListener(this);
        layout.addView(cbxAccelerometer);
 
        setContentView(layout);
    } 
 
    /* 
     * (non-Javadoc) 
     *  
     * @see 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isChecked
    // Update fragment visibility based on current check box state. 
    void updateFragmentVisibility() { 
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        if (mCheckBox1.isChecked()) ft.show(mFragment1);
        else ft.hide(mFragment1);
        if (mCheckBox2.isChecked()) ft.show(mFragment2);
        else ft.hide(mFragment2);
        ft.commit();
    } 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android CheckBox Questions & Answers:

Other Android CheckBox Examples

1:	public void onCheckboxClicked(View view) {
2:	    // Is the view now checked?
3:	    boolean checked = ((CheckBox) view).isChecked();
4:	    
5:	    // Check which checkbox was clicked

Read More

See Code Examples for Android CheckBox Methods: