Hi! I'm trying to do something like task manager for android. Every
task has it's own params (like time, action, and so on). For now the
most important param is a task state: disable/enable. I use usual
checkbox as a state representation. All the tasks are stored in SQLite
database, so I wrote my CustomCursorAdapter. Then I run into mess.
What happens every time during scroll???? I debuged the programm and
saw a lot of bindView calls (in my CustomCursorAdapter). Then I
googled and saw a descision - using boolean array to store the states
of my component (example was about CustomArrayAdapter) but... the deal
is my checkbox change listener disables and enables a corresponding
task. If I use array - the states are correct but the system calls
OnCheckedChangeListener.

Next I downloaded google alarm clock (DeskClock) from GIT and saw how
they'd solved that problem.
They used DontPressWithParentLayout class what is an extension of
LinearLayout. Method setPressed is shown below:
@Override
    public void setPressed(boolean pressed) {
        // If the parent is pressed, do not set to pressed.
        if (pressed && ((View) getParent()).isPressed()) {
            return;
        }
        super.setPressed(pressed);
    }
And usage:
<com.android.deskclock.DontPressWithParentLayout android:id="@+id/
indicator"
        style="@style/alarm_list_left_column"
        android:background="@drawable/clock_selector"
        android:gravity="center"
        android:orientation="vertical">
        <CheckBox android:id="@+id/clock_onoff"
            android:focusable="false"
            android:clickable="false"
            android:background="@drawable/indicator_clock_onoff"
            android:duplicateParentState="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:button="@null" />
        <ImageView android:id="@+id/bar_onoff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="4dip"
            android:src="@drawable/ic_indicator_off" />
    </com.android.deskclock.DontPressWithParentLayout>

In code (bindView method of AdapteR):
 View indicator = view.findViewById(R.id.indicator);
            // Set the initial resource for the bar image.
            final ImageView barOnOff =
                    (ImageView)
indicator.findViewById(R.id.bar_onoff);
            barOnOff.setImageResource(alarm.enabled ?
                    R.drawable.ic_indicator_on :
R.drawable.ic_indicator_off);

            // Set the initial state of the clock "checkbox"
            final CheckBox clockOnOff =
                    (CheckBox)
indicator.findViewById(R.id.clock_onoff);
            clockOnOff.setChecked(alarm.enabled);

            // Clicking outside the "checkbox" should also change the
state.
            indicator.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        clockOnOff.toggle();
 
updateIndicatorAndAlarm(clockOnOff.isChecked(),
                                barOnOff, alarm);
                    }
            });

...
 private void updateIndicatorAndAlarm(boolean enabled, ImageView bar,
            Alarm alarm) {
        bar.setImageResource(enabled ? R.drawable.ic_indicator_on
                : R.drawable.ic_indicator_off);
        Alarms.enableAlarm(this, alarm.id, enabled);
        if (enabled) {
            SetAlarm.popAlarmSetToast(this, alarm.hour, alarm.minutes,
                    alarm.daysOfWeek);
        }
    }

I made something like this....but I left checkbox and remove the
image....and the mess still happens! I just can't believe to work with
list items is so complicated... Why??? How the hell is to solve that
problem?  HEEEELP!
Maybe I shoulw develop my own on\off button and put it in my layout
and override it's onClick method? Or even made it Checkable? But I
still want to use checkbox!!!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to