jeudi 27 septembre 2018

selecting items in custom listView repeat

It's necessary for me. I have custom listview

    public class MisscallListAdapter extends ArrayAdapter<SmsClass>

This is viewHolder :

        private static class ViewHolder {
               TextView number , name , date , count , time;
               ImageButton btnCall , btnSendsms , btnDelete;
               ImageView imageIcon;
               CheckBox checkBox;
        }

In the getView method I try to get the item that clicked by user and put it in an ArrayList like this :

    final ViewHolder finalViewHolder = viewHolder;
    final View finalConvertView = convertView;
    viewHolder.checkBox.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (finalViewHolder.checkBox.isChecked()) {
                selected.add( smsClass );
                Log.i( "kdsfb", "--->   :  " + selected );
            } else {
                for(int i = 0 ; i < selected.size() ; i++){
                    if(selected.get( i ).getId() == smsClass.getId())
                        selected.remove( i );
                }
            }
        }

    } );

The smsClass above is:

    final SmsClass smsClass = getItem(position);

The problem is when I select the first row of the list(just first item) and make it checked then the fifth item checked too and tenth item and ... help, please.




Aucun commentaire:

Enregistrer un commentaire