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

listview 의 child를 다루는 질문입니다.

0 추천

listview 의 한 항목을 클릭하면 그 뷰의 크기가 늘어나게 하고 싶습니다. 펼쳐본다는 느낌으로요.

onItemClick에 getChildAt으로 어찌어찌 되는가 싶더니

전체 항목 수가 화면을 벗어날 경우에 지가 알아서 뷰를 재활용한다나 뭐래나.. 스크롤 시 엄한게 늘어나거나 어플이 종료됩니다. 

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
          long id) {
       // TODO Auto-generated method stub
/*
       JsonNewsItem curItem = (JsonNewsItem) adapter.getItem(position-1);
       String curTitle = curItem.getTitle();
       String curDesc = curItem.getDescription();
       Intent intent = new Intent(context,WholeArticle.class);
       intent.putExtra("title", curTitle);
       intent.putExtra("desc", curDesc);
       startActivityForResult(intent,REQUEST_CODE_ANOTHER);

       RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.heaven);
       */
       
       if(click_focus == -1){
    	   open(parent, view, position, id);
       }
       else if(click_focus != position){
    	   close(parent, view, click_focus, id);
       }

    }
    
    public void open(AdapterView<?> parent, View view, int position, long id){
    	View v = parent.getChildAt(position);
    	v.setMinimumHeight(500);
    	click_focus = position;
    }
    
    public void close(AdapterView<?> parent, View view, int position, long id){
    	View v = parent.getChildAt(position);
    	v.setMinimumHeight(100);
    	click_focus = -1;
    }
    
    
    
}

어디가 잘못된건지 알려주실분 안계신가요? ㅠ

익명사용자 님이 2014년 11월 14일 질문

1개의 답변

0 추천
adapter의 getView 이외의 함수에서 뷰를 임의로 조작하면 정상동작하지 않습니다.

1. getView 함수에서 상황에 따라 각 View의 높이를 조정하게 수정

2. 클릭시 데이터를 알맞게 변경 후 notifyDataSetChanged 호출
익명사용자 님이 2014년 11월 14일 답변
...