Unable to programmatically check a Checkbox in a listview

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

Unable to programmatically check a Checkbox in a listview

Postby hareesh » Wed Dec 02, 2009 5:17 am

Hi,
I am having trouble with setChecked(true) method of a CheckBox.
I have a ListView with Check Boxes as items in it.
When the list activity loads I need to check some of the checkboxes.
I have the positions of those items. I am able to get the text
associated with the checkboxes and also the state (checked/unchecked) of the checkbox using
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ((CheckBox) tagsList.getChildAt(i)).getText().toString(); //here tagsList is the ListView
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

I used
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ((CheckBox) tagsList.getChildAt(i)).setChecked(true);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

to check the checkboxand is not working.
Here's the code..
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void markOldTags() {
  2.  
  3.                 for (int i = 0; i < tagsList.getChildCount(); i++) {
  4.  
  5.                         myCursor.moveToPosition(i); //myCursor is the cursor with the values from database.
  6.  
  7.                         long buffer = myCursor.getLong(myCursor
  8.  
  9.                                         .getColumnIndex(DatabaseAdapter.KEY_ID));
  10.  
  11.                         if (ids.contains(new Long(buffer))) { //ids is the ArrayList with checkbox Ids.
  12.  
  13.                                 showError(((CheckBox) tagsList.getChildAt(i)).getText().toString
  14.  
  15. ());
  16.  
  17. //This is the line that not show any effect
  18.  
  19.                                 ((CheckBox) tagsList.getChildAt(i)).setChecked(true);
  20.  
  21.                         }
  22.  
  23.                 }
  24.  
  25.         }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Hareesh.
hareesh
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 30, 2009 11:57 pm
Location: San Diego

Top

Re: Unable to programmatically check a Checkbox in a listvie

Postby J_R » Fri Jan 22, 2010 12:40 am

I'm having exactly the same problem. Did you sort this out?
http://www.staircase3.com
J_R
Developer
Developer
 
Posts: 32
Joined: Fri Jan 22, 2010 12:37 am

Postby zehunter » Tue Jan 26, 2010 2:50 pm

hi,
can you post your code here? xml file included.
regards,
zehunter
Developer
Developer
 
Posts: 27
Joined: Sun Jan 10, 2010 10:45 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests