마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

curstomer adapter를 만들었는데요..

+1 추천
-----------main activity-----------------
public void db(String todayStr){
  
  allListDto=helper.selectList(todayStr);
  
  /********progressbar********/
  pBar=(ProgressBar) findViewById(R.id.progressBar1);
  progTv=(TextView) findViewById(R.id.progInt);
  int t_count=0;
  int t_docount=0;
  for (int i = 0; i < allListDto.size(); i++) {
   t_count+=allListDto.get(i).getTo_count();
   t_docount+=allListDto.get(i).getTo_docount();
  }
  if(t_count!=0 || t_docount!=0){
   progInt=(t_docount*100)/t_count;
  }else{
   progInt=0;
  }
  
  pBar.setProgress(progInt);
  progTv.setText(" : "+progInt+"%");
  /***************************/
  
  adapter=new CustomerAdapter(MainActivity.this, allListDto, R.layout.listviewunit);
  list=(ListView) findViewById(R.id.listView1);
  list.setAdapter(adapter);
  Log.i("cursor", "db끝");
  
 }


-------------customer adapter----------------------

@Override
 public View getView(int position, View convertView, ViewGroup parent) {
  // TODO Auto-generated method stub
  Log.e("cursor", "customer - getView");
  if(convertView==null){
   convertView=inflater.inflate(layout, parent, false);
  }
  
  ListDto listDto=allListDto.get(position);
  ImageView[] oxArray={oxImg1,oxImg2,oxImg3,oxImg4,oxImg5,oxImg6,oxImg7,oxImg8,oxImg9,oxImg10}; //이미지 선언
  int[] oxImg={R.id.oxImg1,R.id.oxImg2,R.id.oxImg3,R.id.oxImg4,R.id.oxImg5, //이미지 위치
    R.id.oxImg6,R.id.oxImg7,R.id.oxImg8,R.id.oxImg9,R.id.oxImg10};

  if(listDto.getTo_docount()<=0){
   for (int i = 0; i < listDto.getTo_count(); i++) {
    oxArray[i]=(ImageView)convertView.findViewById(oxImg[i]);
    oxArray[i].setImageResource(R.drawable.x);
    Log.e("cursor", "customer-for문"+Integer.toString(listDto.getTo_count()));
   }
   Log.e("cursor", "customer-if문"+Integer.toString(listDto.getTo_count()));
  }else{
   for (int i = 0; i < listDto.getTo_docount(); i++) {
    oxArray[i]=(ImageView)convertView.findViewById(oxImg[i]);
    oxArray[i].setImageResource(R.drawable.o);
   }
   for (int i = listDto.getTo_docount(); i < listDto.getTo_count(); i++) {
    oxArray[i]=(ImageView)convertView.findViewById(oxImg[i]);
    oxArray[i].setImageResource(R.drawable.x);
   }
  }
  TextView to_do=(TextView) convertView.findViewById(R.id.todo);
  to_do.setText(listDto.getTo_do());
  TextView to_unit=(TextView) convertView.findViewById(R.id.tounit);
  to_unit.setText(listDto.getTo_unit());
  
  return convertView;
 }

----------------log cat-------------------

02-05 01:25:08.609: I/cursor(1540): db끝
02-05 01:25:09.409: E/cursor(1540): customer - getView
02-05 01:25:09.509: E/cursor(1540): customer-for문2
02-05 01:25:09.509: E/cursor(1540): customer-for문2
02-05 01:25:09.509: E/cursor(1540): customer-if문2
02-05 01:25:09.719: E/cursor(1540): customer - getView
02-05 01:25:09.719: E/cursor(1540): customer-for문2
02-05 01:25:09.729: E/cursor(1540): customer-for문2
02-05 01:25:09.729: E/cursor(1540): customer-if문2
02-05 01:25:09.929: E/cursor(1540): customer - getView
02-05 01:25:10.019: E/cursor(1540): customer-for문2
02-05 01:25:10.019: E/cursor(1540): customer-for문2
02-05 01:25:10.029: E/cursor(1540): customer-if문2
02-05 01:25:11.179: E/cursor(1540): customer - getView
02-05 01:25:11.179: E/cursor(1540): customer-for문2
02-05 01:25:11.190: E/cursor(1540): customer-for문2
02-05 01:25:11.209: E/cursor(1540): customer-if문2
02-05 01:25:11.739: E/cursor(1540): customer - getView
02-05 01:25:11.770: E/cursor(1540): customer-for문2
02-05 01:25:11.770: E/cursor(1540): customer-for문2
02-05 01:25:11.779: E/cursor(1540): customer-if문2
02-05 01:25:12.809: E/cursor(1540): customer - getView

todolist를 만들었는데요..

리스트가 있고 입력된 수만큼 o x표시를 해줄수있게 만들었거든요..

근데 첫번째줄 x갯수가 새로 입력한 갯수랑 자꾸 같아져서 로그를 찍어보니까...

위에처럼 db메소드를 분리하고 oncreate에서 db메소드를 호출하는데요 customer adapter에서 뭔가 작업이 끝나지가 않는건지.. 계속 반복이 되고있어요..

아직 입문단계라... 원래 이런건지.. 뭐가 문제인건지 모르겠어요..ㅜㅜ

customer adapter는 결과 반환하면 작업이 끝나는게 아닌가요??

곰지0 (210 포인트) 님이 2015년 2월 5일 질문

2개의 답변

+1 추천
 
채택된 답변
위 소스만 가지고는 답변이 힘들듯 합니다...

db를 가져오는 부분에서 어디선가 list를 가져오는데... 어떤 데이터를 가지고 오는지도 잘 모르겠구요...

다만 getView가 반복하여 호출 되는건... getCout에 로그를 찍어 보시면 어느정도 확인은 가능 할 듯 합니다.

getCout도 정상이라면 해당 adapter를 갱신하는 부분이 어디선가 계속 돌고 있을 수도 있을 듯 합니다.

위 소스만 가지고는 이 정도 예상이 될듯 합니다.
디너 (730 포인트) 님이 2015년 2월 5일 답변
곰지0님이 2015년 2월 5일 채택됨
감사합니다. getcount에 찍어보니까 count가 계속 올라가네요.. 더 공부해야겠네요..^^
+1 추천
코드 분석해서 뭐가 잘못됐다라고 한두개만 콕 집어서 말씀드릴수가 없는 상황이네요

전체적으로 코드 작성을 잘못하셨습니다.

무조건 예제만 복붙 하시기 보다 Adapter 에 대한 개념을 먼저 잡으신 후에 코드 작성 하시길 권유 합니다.
Gradler (109,780 포인트) 님이 2015년 2월 5일 답변
아.. 감사합니다. 사실.. 붙여넣기한건아니고.. 너무 제마음대로 짰나봐요..ㅜ 이론적인부분을 더 봐야겠네요..
...