a list of check box

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

a list of check box

Postby chouman » Wed Sep 17, 2008 2:34 am

I am trying to create a list view of check boxes but i am facing a problem where if i select the first check box and then start to scroll. After scrolling down a bit until the selected check box is not visible any more. Then scroll back again until we can see the selected check box, the check box is not selected any more. Anyone know the cause of this?

Here is my LinearLayout that contains the ListView:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout
  5.  
  6. android:id="@+id/layoutEditList"
  7.  
  8. xmlns:android="http://schemas.android.com/apk/res/android"
  9.  
  10. android:layout_width="wrap_content"
  11.  
  12. android:layout_height="wrap_content"
  13.  
  14. android:orientation="vertical"
  15.  
  16. >
  17.  
  18. <ListView android:id="@+id/viewEditList"
  19.  
  20.        android:layout_width="fill_parent"
  21.  
  22.        android:layout_height="250dip"
  23.  
  24.        android:background="#FFFFFF"
  25.  
  26.    />
  27.  
  28. <LinearLayout
  29.  
  30. android:id="@+id/layoutButtons"
  31.  
  32. android:layout_width="wrap_content"
  33.  
  34. android:layout_height="wrap_content"
  35.  
  36. android:layout_gravity="center_horizontal"
  37.  
  38. android:orientation="horizontal"
  39.  
  40. >
  41.  
  42. <Button
  43.  
  44. android:id="@+id/btnEditMembers"
  45.  
  46. android:layout_width="wrap_content"
  47.  
  48. android:layout_height="wrap_content"
  49.  
  50. android:text="Button"
  51.  
  52. android:textSize="13dip"
  53.  
  54. >
  55.  
  56. </Button>
  57.  
  58. <Button
  59.  
  60. android:id="@+id/btnEditMembersCancel"
  61.  
  62. android:layout_width="wrap_content"
  63.  
  64. android:layout_height="wrap_content"
  65.  
  66. android:text="Cancel"
  67.  
  68. android:textSize="13dip"
  69.  
  70. >
  71.  
  72. </Button>
  73.  
  74. </LinearLayout>
  75.  
  76. </LinearLayout>
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


and the checkbox layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout
  5.  
  6. android:id="@+id/layoutCheckBox"
  7.  
  8. android:layout_width="fill_parent"
  9.  
  10. android:layout_height="fill_parent"
  11.  
  12. android:orientation="vertical"
  13.  
  14. xmlns:android="http://schemas.android.com/apk/res/android"
  15.  
  16. >
  17.  
  18. <CheckBox
  19.  
  20. android:id="@+id/chkboxGroupContactName"
  21.  
  22. android:layout_width="wrap_content"
  23.  
  24. android:layout_height="wrap_content"
  25.  
  26. android:text="CheckBox"
  27.  
  28. android:textColor="#000000"
  29.  
  30. >
  31.  
  32. </CheckBox>
  33.  
  34. </LinearLayout>
  35.  
  36.  
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Is there a setting for checkbox that i need to do?
chouman
Developer
Developer
 
Posts: 27
Joined: Thu Jan 03, 2008 2:59 pm

Top

Postby plusminus » Wed Sep 17, 2008 4:18 am

No, the reason for that is that the checboxes get destroyed when the get out of thsi visible rect. Coming back it is a new one. Therefor you need to store the "checked"-state in i.e. a [font=Courier New]boolean[][/font] Array.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby chouman » Thu Sep 18, 2008 12:07 am

Got it plusminus, thanks for the help
chouman
Developer
Developer
 
Posts: 27
Joined: Thu Jan 03, 2008 2:59 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests