Na  Jun Yeop Na Jun Yeop - 3 years ago 83
Android Question

Android lost of check state after scrolling

Whenever scrolling up and down, I lose check state of checkbox.

I can't solve this problem for two days......

Please help me

Here is my code.

public View getView(final int position, View view, ViewGroup parent) {

context = parent.getContext();

inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

if (view == null) {

holder = new ViewHolder();

view = inflater.inflate(R.layout.custom_llistview, parent, false);

holder.img_view = (ImageView) view.findViewById(;
holder.txt_view = (TextView) view.findViewById(;
holder.checkbox = (CheckBox) view.findViewById(;

else {
holder = (ViewHolder)view.getTag();



holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {

check_flag_arr[position] = isChecked;
else {
check_flag_arr[position] = isChecked;

file_path = list_item.get(position).getFile_path();
Bitmap showImage = BitmapFactory.decodeFile(file_path);


list_contents = file_path.substring(45, 65);

return view;

And detail explanation will be a great pleasure to me.

I must solve this problem.

Thanks for watching my post.

Answer Source

whenever you scroll setOnCheckedChangeListener is called

Removing setOnCheckedChangeListener and implimant setOnClickListener

holder.checkbox.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                    if (holder.checkbox.isChecked()) {
                         check_flag_arr[position] = true;
                    } else {
                        check_flag_arr[position] = false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download