Android CompoundButton - 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 CompoundButton 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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getVisibility, setVisibility, setChecked
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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isChecked, setOnCheckedChangeListener, setChecked, setEnabled
            case BluetoothAdapter.STATE_TURNING_OFF:
                mSwitch.setEnabled(false);
                break; 
            case BluetoothAdapter.STATE_OFF:
                setChecked(false); 
                mSwitch.setEnabled(true);
                break; 
            default: 
                setChecked(false); 
                mSwitch.setEnabled(true);
        } 
    } 
 
    private void setChecked(boolean isChecked) {
        if (isChecked != mSwitch.isChecked()) {
            // set listener to null, so onCheckedChanged won't be called 
            // if the checked status on Switch isn't changed by user click 
            if (mValidListener) {
                mSwitch.setOnCheckedChangeListener(null);
            } 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setLayoutParams, setButtonDrawable, setBackgroundDrawable
     
    // create a new ImageView for each item referenced by the Adapter 
    public View getView(int position, View convertView, ViewGroup parent) {
        ToggleButton imageButton;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	imageButton = new ToggleButton(mContext);
        	imageButton.setLayoutParams(new GridView.LayoutParams(110, 110));
        	/**imageButton.setScaleType(ToggleButton.ScaleType.CENTER_CROP); 
        	imageButton.setPadding(8, 8, 8, 8);*/ 
        } else { 
        	imageButton = (ToggleButton) convertView;
        } 
         
        imageButton.setBackgroundDrawable(null);
        imageButton.setButtonDrawable(mThumbIds[position]);
        return imageButton;
    } 
 
    // references to our images 
    private Integer[] mThumbIds = {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android CompoundButton Questions & Answers:

Other Android CompoundButton Examples

1:	ToggleButton toggle = (ToggleButton) findViewById(R.id.togglebutton);
2:	toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
3:	    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
4:	        if (isChecked) {
5:	            // The toggle is enabled

Read More

See Code Examples for Android CompoundButton Methods: