2013-03-27 4 views
0

확장 가능한 목록을 표시하는 응용 프로그램을 만들고 있습니다. 사실 개체에는 어떤 자식도 없을 때가 있습니다. 그래서 내 확장 목록에 자식 요소가있는 요소 만 표시하고 싶습니다. 확장형 목록보기 android

public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { 

    // Check if the object as child 
    System.out.println("Result list :: " + mParent.get(i).getListe()); 

      if(mParent.get(i).getListe().isEmpty()){ 
     return null; 
    } 

    if (view == null) { 
     view = inflater.inflate(R.layout.list_item_parent, viewGroup,false); 
    } 



    TextView textView = (TextView) view.findViewById(R.id.list_item_text_view); 
    //"i" is the position of the parent/group in the list 
    textView.setText(getGroup(i).toString()); 

    // Set the Image View with the brand logo 
    ImageView logo = (ImageView) view.findViewById(R.id.brandlogo); 

    // Set image Source 
    logo.setImageResource(mParent.get(i).getLogoPath()); 

    // Set Image size  
    logo.getLayoutParams().height = 42; 
    logo.getLayoutParams().width = 226; 

    //return the entire view 
    return view; 
} 

거기인가 : 내가 getGroupView의 함수 내 경우를 넣어 시도하고 객체가 자식이없는 경우, 내가 null을 반환하지만 NullPointerException이 오류가 ... 여기

는 기능입니다 방법이 기능을 건너 뛸까요? getGroupCount() 함수에서

답변

1

덕분 childes (상품 번호 childes을 갖는다)이있는 항목의 수를 반환한다.
그리고 getGroubView()에서 올바른보기를 반환하십시오 (여기서 null을 반환하지 마십시오).

+0

'올바른보기로 돌아 가기'란 무엇을 의미합니까? –

+0

해당 위치에있는 자식이있는보기 – JafarKhQ

+0

하지만 그룹이없는 경우 어떤 자식으로 반환합니까? –

관련 문제