Weird problem with Custom Listview and CheckedTextView

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Weird problem with Custom Listview and CheckedTextView

Postby pratik goswami » Fri May 08, 2009 11:45 am

Hi,

I have created a customized list view with checkbox fields with help of CheckedTextView. I was socked when I show that check boxes are not being selected/checked according to list's selection. When I click on 1st row - 4th row's checkbox gets checked. In short sequence is not maintained. The code with I am working is as below
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. lw.setOnItemClickListener(new OnItemClickListener() { //lw is the ListView Object.
  2.         public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
  3.                 View checkedtext = ((TableRow)((TableLayout) arg1).getChildAt(0)).getChildAt(2);                               
  4.                 if (checkedtext != null && checkedtext instanceof CheckedTextView) {
  5.                         CheckedTextView cv = (CheckedTextView) checkedtext;
  6.                         cv.setChecked(!cv.isChecked());
  7.                 }
  8.         }
  9. });  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Here is the layout xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/tableLy"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical"
  7. android:stretchColumns="1">
  8. >
  9.         <TableRow
  10.         android:id="@+id/tableRw"
  11.         android:layout_width="fill_parent"
  12.         android:layout_height="80px"
  13.         android:orientation="horizontal"               
  14.         >
  15.                 <ImageView
  16.                 android:id="@+id/imgView1"
  17.                 android:layout_width="wrap_content"
  18.                 android:layout_height="wrap_content"           
  19.                 android:layout_gravity="left"
  20.                 android:padding="3dip"
  21.                 >
  22.                 </ImageView>           
  23.                 <LinearLayout
  24.         android:layout_width="fill_parent"
  25.         android:layout_height="wrap_content"
  26.         android:orientation="vertical"
  27.                 android:padding="3dip"
  28.                 >
  29.                 <TextView android:id="@+id/txtview1"
  30.                 android:textSize="16px"        
  31.                 android:textColor="#fff"        
  32.                 android:layout_width="fill_parent"
  33.                 android:layout_height="wrap_content"
  34.                 />             
  35.                 <TextView android:id="@+id/txtview2"
  36.                 android:textSize="12px"
  37.                 android:textStyle="italic"
  38.                 android:layout_width="fill_parent"
  39.                 android:layout_height="wrap_content"
  40.                 />              
  41.                 </LinearLayout>
  42.                
  43.                 <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
  44.         android:id="@+id/PostedCheckBox"
  45.         android:layout_width="fill_parent"
  46.         android:layout_height="wrap_content"
  47.         android:gravity="center_vertical"
  48.         android:checkMark="?android:attr/listChoiceIndicatorMultiple"
  49.         android:paddingLeft="6dip"
  50.         android:paddingRight="6dip"
  51.         />
  52.                
  53.         </TableRow>
  54. </TableLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4


Is it bug or am I making any mistake? Please help me to sort out this problem.

Thanks
Pratik.
pratik goswami
Junior Developer
Junior Developer
 
Posts: 19
Joined: Mon Sep 22, 2008 2:54 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests