1

I encountered a problem with a ‍ListView. There is a list of check boxes in the list, I would like to get an item checked and pass the value to another activity. When I check the last item of 16 to 28 I get nothing but when I check all item in this case no problem ? and sometimes I get only 5 to 10 first element

Notice: the list size is variable

    SparseBooleanArray mCheckStates;  

  Context context;
  List<File> objects ;

  public CustomList(Context paramContext, int paramInt, List<File> paramList )
  {
    super(paramContext, 0, paramList);
    this.context = paramContext;
    this.objects = paramList;

    mCheckStates = new SparseBooleanArray(
            objects.size()); 


  }

     @Override
      public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)         
      {
          View row = paramView;
          ViewHolder holder= null;
          if (row == null) {
              LayoutInflater vi = (LayoutInflater) context
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

                       row = vi.inflate(R.layout.itemcheck, null);

                holder = new ViewHolder();

                holder.CheckName = (CheckBox) row.findViewById(R.id.checkbox_android);
                holder.FileName = (TextView) row.findViewById(R.id.textView1);

                row.setTag(holder);


          }
          else
          {
              holder = (ViewHolder)row.getTag();
          }

          holder.FileName.setText(((File)this.objects.get(paramInt)).getName());

          Toast.makeText(context, ""+ ((File)this.objects.get(paramInt)).getName(), 300).show();


          holder.CheckName.setTag(paramInt);
          holder.CheckName.setChecked(mCheckStates.get(paramInt, false));
          holder.CheckName.setOnCheckedChangeListener(this); 

        return row;
      }
      private class ViewHolder
        {
            TextView FileName;
            CheckBox CheckName;

        }


      public boolean isChecked(int position) {
          return mCheckStates.get(position, false);
      }

      public void setChecked(int position, boolean isChecked) {
          mCheckStates.put(position, isChecked);
          notifyDataSetChanged();

      }

      public void toggle(int position) {
          setChecked(position, !isChecked(position));

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

       mCheckStates.put((Integer) buttonView.getTag(), isChecked);  

    }

    }
5
  • I Suggest you to use an ImageView instead of CheckBox and add Callback to your Class on Clicking of the ImageView
    – Manu
    Apr 15, 2015 at 8:59
  • I did not understand your approach ,you can show me how i can do that !
    – M0M0
    Apr 15, 2015 at 9:04
  • try putting this line holder.CheckName.setTag(paramInt); before this line row.setTag(holder); Apr 15, 2015 at 9:06
  • @Scion of Ikshvaku ??
    – M0M0
    Apr 15, 2015 at 9:16
  • what is the code you use to get all the checked items ?
    – dora
    Apr 15, 2015 at 13:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.