[android-developers] Checkbox problem

2011-04-07 Thread grevenilvec
I have a big Problem with my Listview and its Checkboxes... Every
thing is shown and works fine, until I click on one of the Checkboxes.
Then other Boxes are checked and sometimes even without checking the
one, I clicked.
I searched the web, but didn't find a solution that is working. Now
I'm hoping, someone of you, Guys, would be able to help to solve my
problem.

Enclosed is the Code of my Customadapter, which is used for filling
the list.

package org.openintents.filemanager;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class CustomSettingsAdapter extends BaseAdapter{

 private static ArrayList settingsArrayList;
 private LayoutInflater mInflater;

 public CustomSettingsAdapter(Context context, ArrayList
sitems)
 {
  settingsArrayList = sitems;
  mInflater = LayoutInflater.from(context);
 }

 public int getCount()
 {
  return settingsArrayList.size();
 }

 public Object getItem(int position)
 {
  return settingsArrayList.get(position);
 }

 public ArrayList getItemList()
 {
  return settingsArrayList;
 }

 public long getItemId(int position)
 {
  return position;
 }

 public View getView(final int position, View convertView, ViewGroup
parent) {
  final ViewHolder holder;
  if (convertView == null)
  {
   convertView = mInflater.inflate(R.layout.settings_item, null);
   holder = new ViewHolder();
   holder.txtName = (TextView)
convertView.findViewById(R.id.setting_name);
   holder.details = (TextView)
convertView.findViewById(R.id.setting_detail);
   holder.cb = (CheckBox) convertView.findViewById(R.id.check);
   convertView.setTag(holder);
  }
  else
  {
   holder = (ViewHolder) convertView.getTag();
  }

  holder.txtName.setText(settingsArrayList.get(position).getName());
  holder.details.setText(settingsArrayList.get(position).getPath());
  holder.cb.setChecked(settingsArrayList.get(position).getState());
  int[]tags = new int[2];
  tags[0]= position;
  tags[1]= 0;
  holder.cb.setTag(tags);

  holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

   @Override
   public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {

int[]i=(int[])holder.cb.getTag();
settingsArrayList.get(i[0]).setState(isChecked);
notifyDataSetChanged();
   }
  });

  return convertView;
 }

 static class ViewHolder
 {
  TextView txtName;
  TextView details;
  CheckBox cb;
 }
}

Thank you very much in advance for helping.
Best regards
Tobi

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


Re: [android-developers] CheckBox problem

2010-10-13 Thread TreKing
On Wed, Oct 13, 2010 at 5:52 AM, Ahmed Shoeib  wrote:

> what is the problem ???


ListView recycles views so the one you're setting the check state on may be
re-used and re-drawn somewhere else. Don't use findViewWithTag() - set the
checked state in getView().

-
TreKing  - Chicago
transit tracking app for Android-powered devices

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

[android-developers] CheckBox problem

2010-10-13 Thread Ahmed Shoeib
hi all,

i have custom ArrayAdapter to make listView each row contain ( image &
text & checkBox )

i made the xml file to make the standard layout for row

and make the default visibility for checkBox false

in getView function that draw the listview

get the checkBox using id and assign specific tag for it to enable me
to get it

on the onListItemClick function

i made this code :

   CheckBox check = (CheckBox)v.findViewWithTag(position);
check.setVisibility(0);

to get the current checkbox and make it visible

but when i choose specific row i found that some of the other rows
checkbox become visible
and current row checkbox not change ??

what is the problem ???
how can isolve it

thanks



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