I'm trying to do something similar, but I can't get my custom view
class to see the click events (I set breakpoints in the constructor
and I get to those) but I never hit breakpoints in the toggle() or
setChecked() methods.

Ken

On Jun 1, 6:48 pm, zealot <zhentao.hu...@gmail.com> wrote:
> Hi,
>
> I've encountered same problem. Solution is:
>
> Define your resource like this:
> <?xml version="1.0" encoding="utf-8"?>
> <view
>   class="your.owner.view"
>   xmlns:android="http://schemas.android.com/apk/res/android";
>   android:orientation="horizontal"
>   android:layout_width="fill_parent"
>   android:layout_height="wrap_content">
>         <CheckBox
>                 android:focusable="false"
>                 android:clickable="false"
>                 android:layout_width="wrap_content"
>                 android:layout_height="wrap_content"
>                 android:gravity="center_vertical"
>             android:layout_marginRight="5dip"
>                 android:id="android:id/checkbox"
> android:layout_marginLeft="5dip"/>
>         <TextView
>                 android:id="@+id/person_name"
>                 android:text="test"
>                 android:layout_width="wrap_content"
>                 android:layout_height="wrap_content"
>                 android:gravity="center_vertical"
>                 android:textSize="18dip"
> android:layout_marginLeft="5dip"/>
> </view>
>
> Define your view class
> public class your.owner.view extends LinearLayout implements Checkable
> {
>        // Add your constructors
>
>         @Override
>         public boolean isChecked() {
>                 // TODO Auto-generated method stub
>                 return this.checked;
>         }
>
>         @Override
>         public void setChecked(boolean checked) {
>                 // TODO Auto-generated method stub
>                 getCheckBox().setChecked(checked);
>                 this.checked = checked;
>                 refreshDrawableState();
>
>                // Append your event handler here
>         }
>
>         @Override
>         public void toggle() {
>                 // TODO Auto-generated method stub
>                 //getCheckBox().setChecked(!checked);
>                 setChecked(!checked);
>         }
>
>         private CheckBox getCheckBox()
>         {
>
>                 if (checkbox == null)
>                 {
>                         checkbox = (CheckBox) 
> findViewById(android.R.id.checkbox);
> //                      checkbox.setFocusable(false);
> //                      checkbox.setClickable(false);                 // The 
> check box
> should decline the click event, hence the list item could be clicked.
>                 }
>                 return checkbox;
>         }
>
>         private CheckBox checkbox;
>         private boolean checked;
>
> }
>
> zealot
>
> On 5月28日, 下午7时58分, praneet pandit <praneetpan...@gmail.com> wrote:
>
> > and the romain guy video you looking 
> > forhttp://code.google.com/events/io/2009/sessions/TurboChargeUiAndroidFa...
>
> > regards,
> > Ravi - The PPite
> > PathPartner Tech
>
> > On May 25, 9:15 am, Paul <paul.rash...@gmail.com> wrote:
>
> > > This has to do with the fact that ListView recycles views.  View
> > > Romain Guy's Google I/O talk about ListView when it comes out.  It is
> > > really good and explains exactly why you're seeing this happen.
>
> > > On Apr 30, 10:20 am, David <davideberl...@googlemail.com> wrote:
>
> > > > Hey,
>
> > > > I am facing a very mysterious Problem. I am using a ListView with
> > > > CheckBoxes that can be clicked to select people.
> > > > The row layout is the following:
>
> > > > <?xml version="1.0" encoding="utf-8"?>
> > > > <LinearLayout
> > > >   xmlns:android="http://schemas.android.com/apk/res/android";
> > > >   android:orientation="horizontal"
> > > >   android:layout_width="fill_parent"
> > > >   android:layout_height="wrap_content">
> > > >         <CheckBox
> > > >                 android:focusable="false"
> > > >                 android:onClick="onSelectPerson"
> > > >                 android:layout_width="wrap_content"
> > > >                 android:layout_height="wrap_content"
> > > >                 android:gravity="center_vertical"
> > > >             android:layout_marginRight="5dip"
> > > > android:layout_marginLeft="5dip"/>
> > > >         <TextView
> > > >                 android:id="@+id/person_name"
> > > >                 android:text="test"
> > > >                 android:layout_width="wrap_content"
> > > >                 android:layout_height="wrap_content"
> > > >                 android:gravity="center_vertical"
> > > >                 android:textSize="18dip" 
> > > > android:layout_marginLeft="5dip"/>
> > > > </LinearLayout>
>
> > > > As long as the amount of rows doesen't exceed the screen size (-> no
> > > > scrolling) everything works just fine.
> > > > But as soon as I have more rows then the screen size (-> some rows are
> > > > hidden and have to be scrolled to).
> > > > I have a very mysterious phenomenon:
>
> > > > If I check the top row and scroll down some of the previously hidden
> > > > rows are randomly checked too. If I scroll up again, again some of the
> > > > before hidden rows are randomly vhecked (theCheckBoxI clicked in
> > > > first place may or may not still be checked).
> > > > Also the registered onSelectPerson callback is only called for the
> > > > CheckBoxes I really click. The other CheckBoxes just change their
> > > > state to "checked" without calling the callback method.
> > > > I have the same phenomenom on the Archos IT 5 and the Nexus One.
>
> > > > This must have something to do with the ListView implementation but I
> > > > can't quite figure out what the problem is.
> > > > Can anyone help?
>
> > > > Best Regards
>
> > > > David
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Android Developers" group.
> > > > To post to this group, send email to android-developers@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > android-developers+unsubscr...@googlegroups.com
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/android-developers?hl=en
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to android-developers@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > android-developers+unsubscr...@googlegroups.com
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/android-developers?hl=en

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

Reply via email to