Problem with checkbox list

Put your problem here if it does not fit any of the other categories.

Problem with checkbox list

Postby saiko6996 » Tue Feb 19, 2008 8:46 pm

Hi every body!

I have read the posts:
http://www.anddev.org/checkboxifiedtext ... -t695.html
http://www.anddev.org/checkbox_-_how_to ... -t739.html

I have done a list of checkbox and it works, but I don't like how it works. I'm going to explain what it does:

I want to know what checkboxes are selected, so I give to the checkboxes one identifier in getView() method. Also in this method I have an ArrayList where I save the checkboxes with their identifier. The problem is that if I have created 3 checkboxes, the getView() method runs 6 times, so the application duplicate the id of the checkboxes, for example:
I create the next checboxes: checkbox1, checkbox2, checkbox3
The ArrayList of checkboxes has: (0,checkbox1),(1,checkbox2),(3,checkbox2),(4,checkbox1),(5,checkbox2),(6,checkbox3)

Why the getView() method runs more times?
In the code of bluefloyd8 also the getView method runs more times.

Is other way to do this?

The checkboxes ArrayList I use in the ListActivity when I choose a menu option to know what checkbox is checked:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. for(int i=0; i<thecheckboxes.size();i++){
  3.  
  4.                         if(thecheckboxes.get(i).isChecked()){                          
  5.  
  6.                                 ........                       
  7.  
  8.                         }
  9.  
  10.                 }      
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


I have one adapter where I do the getView() method like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public View getView(int position, View convertView, ViewGroup parent) {
  3.  
  4.                 // TODO Auto-generated method stub
  5.  
  6.                 Element p = listE.get(position);
  7.  
  8.         return generarFila(p.getElement());
  9.  
  10.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

In generarFila() method I give one id to the checkboxes:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private List<CheckBox> checkboxes=new ArrayList<CheckBox>();
  2.  
  3. ......
  4.  
  5. CheckBox cbox=new CheckBox(mContext);
  6.  
  7.                 cbox.setId(p);
  8.  
  9. checkboxes.add(p, cbox);
  10.  
  11.                 p++;
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
saiko6996
Freshman
Freshman
 
Posts: 6
Joined: Tue Feb 19, 2008 7:41 pm

Top

Postby plusminus » Tue Feb 19, 2008 9:30 pm

Hello saiko6996,

check whether convertView is null or not.
If it isn't it contains the View created before, whoch gets the chance to be "refreshed".

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 saiko6996 » Wed Feb 20, 2008 1:09 pm

Hello!!

I watch the convertView in getView() method and always is null. From first execution until last execution is null. It's that normal?

Thankssss
saiko6996
Freshman
Freshman
 
Posts: 6
Joined: Tue Feb 19, 2008 7:41 pm

Postby plusminus » Wed Feb 20, 2008 6:56 pm

^^ maybe.

As far as I know convertView is not null, when the View only gets invalidated. That is to avoid additional Object-Creation what sooner or later causes a GC!.

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 saiko6996 » Thu Feb 21, 2008 12:13 pm

Hi!!!

it's any way to solve this problem???

Thankss
saiko6996
Freshman
Freshman
 
Posts: 6
Joined: Tue Feb 19, 2008 7:41 pm

Postby nk » Fri Mar 14, 2008 4:16 pm

i am stuck here too :/
nk
Junior Developer
Junior Developer
 
Posts: 21
Joined: Tue Jan 29, 2008 3:23 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 9 guests