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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > 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 [email protected] > > To unsubscribe from this group, send email to > > [email protected] > > 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 [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

