ZuoAndroid / android-query

Automatically exported from code.google.com/p/android-query
0 stars 0 forks source link

Missing support for CompoundButton / extend checked() support to Checkable implementations #115

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I use some Toggle buttons, I was missing a getter to set the listeners:

    /**
     * Gets the current view as a compound button.
     *
     * @return Button
     */
    public CompoundButton getCompoundButton(){
        return (CompoundButton) view;
    }

Additionally, instead of limiting checked() to CompoundButton subclasses, you 
could allow it to affect all Checkable implementations:

    /**
     * Set checked state of a compound button.
     *
     * @param checked state
     * @return self
     */
    public T checked(boolean checked){

        if(view instanceof android.widget.Checkable){
            android.widget.Checkable cb = (android.widget.Checkable) view;
            cb.setChecked(checked);
        }

        return self();
    }

    /**
     * Get checked state of a compound button.
     *
     * @return checked
     */
    public boolean isChecked(){

        boolean checked = false;

        if(view instanceof android.widget.Checkable){
            android.widget.Checkable cb = (android.widget.Checkable) view;
            checked = cb.isChecked();
        }

        return checked;
    }

Original issue reported on code.google.com by marvinl...@gmail.com on 12 Jan 2013 at 4:01