listview에서 스크롤시 체크가 중복되는 문제로 고통받고 있습니다. PUB의 도움이 절실합니다.  


리스트를 띄운 후 체크를 하면 화면에 보이는 리스트만큼 지나서 ( 예를들면 한화면에 7개의 리스트가 보이면 8번째에 )체크가 또 되어 버립니다. 이렇게 화면을 내릴수록 반복되서 체크가 되어 버립니다. 체크는 맨 첫번째에 한번밖에 안했는데 말이죠..


원인은 안드로이드가 리스트를 뿌리는 방식이 화면만큼만 리스트를 만들고 스크롤을 하면 그 화면을 재사용하는 방식때문입니다. 

이를 해결하기 위해서 ARRAYLIST를 사용ㅎ 해당 POSITION에 CHECK / UNCHECK 여부를 저장을 해놨습니다. 


그런데 이 ARRAYLIST가 중복해서 값이 들어가는 문제가 생기더군요. 스크롤을 아래로 했다가 다시 위로 올리면

SelectMotherChkList=[0=UnCheck2UN, 0=UnCheck2UN, 1=UnCheck2UN, 1=UnCheck2UN, 2=UnCheck2UN, 2=UnCheck2UN, 3=UnCheck2UN, 3=UnCheck2UN, 4=UnCheck2UN, 4=UnCheck2UN, 5=UnCheck2UN, 5=UnCheck2UN, 6=UnCheck2UN, 6=UnCheck2UN, 7=UnCheck2UN, 7=UnCheck2UN, 8=UnCheck2UN, 9=UnCheck2UN, 10=UnCheck2UN, 11=UnCheck2UN, 12=UnCheck2UN, 13=UnCheck2UN, 14=UnCheck2UN, 15=UnCheck2UN, 16=UnCheck2UN, 17=UnCheck2UN, 18=UnCheck2UN]


이런식으로 0번째 1번째 2번째 3번째 4번째....    POSITION에 값이 중복되서 들어갑니다. ARRAYLIST.SET으로 해봤고. 해당값을 ARRAYLIST.REMOVE(POSITION)으로 값을 지우고 ARRAYLIST.ADD(POSITION)으로 했는데도 값이 중복해서 들어가버리네요.


SelectMotherChkList <- PUBLIC 으로 했다가 빼 보다가도 해봤는데도 중복해서 들어가는건 여전하네요. 중복체크되구요. ㅠㅠ

SelectMotherChkList = new ArrayList<String>(); 


만들고 있는게 ExpandableListView 안에 ImageView와 TextView를 커스텀으로 넣었습니다. ImageView는 CHECK시 UNCHECK시 이미지가 각각 따로 만들어 체크효과를 만들었습니다. CHECKBOX는 이벤트를 먹어버리더군요.


벌써 3일째 이문제로 고통이 이루 말할수 없습니다. ㅠㅠ (뷰홀더를 써라는 말을 들었는데 뷰홀더가 먼지, 또 뷰홀더를 꼭 써야 하는지도 모르겠습니다.)


해당 소스 입니다.==========================================================================


//부모 열 만들기

@Override

public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

final int Positon = groupPosition;

final View v = convertView;

int GroupCount = getGroupCount();

String headerTitle = (String) getGroup(groupPosition);

if (convertView == null) {

LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

convertView = infalInflater.inflate(R.layout.list_group, null);

System.out.println("체크박스 생성");

}


TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader);

lblListHeader.setTypeface(null, Typeface.BOLD);

lblListHeader.setText(headerTitle);

SelectMotherChkList.add(Positon, "UnCheck");

if(SelectMotherChkList.get(Positon).equals("") || SelectMotherChkList.get(Positon).equals(null) ){

SelectMotherChkList.add(Positon, Positon+"=CHECK1");

}else{

if(SelectMotherChkList.get(Positon).equals("UnCheck")){

SelectMotherChkList.remove(SelectMotherChkList.get(Positon));

System.out.println("전 = SelectMotherChkList"+SelectMotherChkList);

SelectMotherChkList.add(Positon, Positon+"=UnCheck2UN");

System.out.println("후 = SelectMotherChkList"+SelectMotherChkList);

}else{

SelectMotherChkList.remove(SelectMotherChkList.get(Positon));

SelectMotherChkList.add(Positon, Positon+"=Check3CHK");

}

}

if(SelectMotherChkList.get(Positon).equals("Check")){

ImageView chkBtn = (ImageView) convertView.findViewById(R.id.Mcheckbox);

Drawable d = _context.getResources().getDrawable(R.drawable.unchkbox);

            Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

}else{

ImageView chkBtn = (ImageView) convertView.findViewById(R.id.Mcheckbox);

    Drawable d = _context.getResources().getDrawable(R.drawable.chkbox);

            Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

}

System.out.println("SelectMotherChkList="+SelectMotherChkList);

ImageView chkBtn = (ImageView) convertView.findViewById(R.id.Mcheckbox);

TextView GroupNum = (TextView) convertView.findViewById(R.id.GroupNum);

chkBtn.setOnClickListener(new ImageView.OnClickListener(){

     public void onClick(View v) {

      if(SelectMotherChkList.get(Positon).equals("UnCheck")){

     

      System.out.println("체크 입니다.");

      System.out.println(Positon);

     

      SelectMotherChkList.set(Positon, "Check");

      ImageView imgview = (ImageView) v.findViewById(R.id.Mcheckbox);

          Drawable d = _context.getResources().getDrawable(R.drawable.chkbox);

                 Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

                 

                 imgview.setImageBitmap(null);

                 imgview.setImageResource(0);

                 imgview.setImageBitmap(bitmap);

                 imgview.invalidate();

               

      }else{

      System.out.println("언체크 입니다.");

      SelectMotherChkList.set(Positon, "UnCheck");

      ImageView imgview = (ImageView) v.findViewById(R.id.Mcheckbox);

          Drawable d = _context.getResources().getDrawable(R.drawable.unchkbox);

                 Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

                 

                 imgview.setImageBitmap(null);

                 imgview.setImageResource(0);

                 imgview.setImageBitmap(bitmap);

                 imgview.invalidate();

      }

     }

      });

return convertView;

}