Code example for CheckBox

Methods: getContextsetOnLongClickListenersetCheckedsetOnCheckedChangeListener

    private void setupCheckbox(CheckBox view, Cursor cursor, final int id) {
        int value = cursor.getInt(ENABLED_COLUMN);
        boolean checked = value > 0;
        view.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View view) {
                return false; 
        final Context context = view.getContext();
        view.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                adapter.update(id, b);
                broadcast.send(context, adapter);
    private void clearPreviousListeners(CheckBox checkbox) {
        // First clear the listener of any recycled views. 
    // FIX 02/09/2011 Hmm. This doesn't seem very generic or safe. 
    private int getId(Cursor cursor) {
        return cursor.getInt(0);
Stop searching for code, let great code find you!  Add Codota to your java IDE