mardi 21 juillet 2015

When the GridView scrolls, it changes CheckBox Selections

Accualy i read all posts but i cant solution my problem. And i need help.

I have got gridview. I am filling grids a baseadapter. My grids has got ImageViews and CheckBoxes. I am LongTouching any grid and checking CheckBox. All is done here.

But when i scroll the gridview all selections changing. I try some solution from other posts but i can't fix problem.

Adapter GetView Method;

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    View grid;

   if (convertView == null) {
        grid = new View(mContext);
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        grid = inflater.inflate(R.layout.mygrid, parent, false);
    } else 
    {
        grid = (View) convertView;
    }

    ImageView imageView = (ImageView) grid.findViewById(R.id.imagepart);
    final CheckBox ch = (CheckBox)grid.findViewById(R.id.checkBox);
    ch.setTag(position);

    HashMap<String,String> tar;
    tar = data.get(position);

    imageLoader.DisplayImage(tar.get(FragmentB.FOTOYOL),imageView);

    grid.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            CheckBox chh = (CheckBox)v.findViewWithTag(position);
            chh.setChecked(true);
            return false;
        }
    });

    return grid;
}

If I delete (convertView == null) line and remove else block then, checks not changing but when checkbox is going to unseen because of scroll, returning with scroll to that checkbox and it is unchecked. Not permanently checked.

I need big help. Thank you...




Aucun commentaire:

Enregistrer un commentaire