Do not handle the checked state yourself. ListView recyles the view
which can cause trouble. Lookup setChoiceMode() instead and refer to
the ApiDemos for examples.

On Sun, Feb 15, 2009 at 5:42 AM, Shams <shammi.theod...@gmail.com> wrote:
>
> Hello,
> I have a custom multi-select listview with two lines per row and a
> checkbox in the first line. When I click on the checkbox, the checbox
> does not get checked. But the list items get checked/ unchecked. I
> want to check the checkbox corresponding to the row I clicked. If I
> use findViewById() in onListItemClick(), it does not find the correct
> checkbox. I click on a click and some other row gets checked. How can
> I get to check the correct row. Below is my main.xml and
> onListItemClick() code:
>
> Main.xml
> --------------
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout
>     xmlns:android="http://schemas.android.com/apk/res/android";
>     android:layout_width="fill_parent"
>     android:layout_height="wrap_content"
>     android:orientation="vertical"
>     android:paddingTop="5dip"
>     android:paddingBottom="5dip"
>     android:paddingLeft="5dip"
>     >
>     <CheckedTextView
>         android:id="@+id/title"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:textAppearance="?android:attr/textAppearanceLarge"
>         android:checkMark="?android:attr/listChoiceIndicatorMultiple"
>         />
>     <TextView
>         android:id="@+id/desc"
>         android:layout_width="fill_parent"
>         android:layout_height="wrap_content"
>         android:layout_below="@+id/title"
>         android:textAppearance="?android:attr/textAppearanceSmall"
>         />
> </LinearLayout>
>
> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> protected void onListItemClick(ListView l, View v, int position, long
> id) {
>        super.onListItemClick(l, v, position, id);
>        CheckedTextView cbox = (CheckedTextView)v.findViewById(R.id.title);
>        if(cbox.isChecked())
>                cbox.setChecked(false);
>        else
>                cbox.setChecked(true);
>
>        v.refreshDrawableState();
> }
>
> >
>



-- 
Romain Guy
Android framework engineer
romain...@android.com

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

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

Reply via email to