2012-12-01 3 views
0

ArrayList를 구성원으로 포함하는 사용자 지정 목록보기 어댑터가 있습니다.사용자 지정 목록보기 어댑터의 개체 배열

각 게임은 라운드에 속합니다. 내 말은 :

public class GameSummary 
{ 
String round; 
Game game; 
} 

그래서 실제로, 나는 라운드 헤더 아래의 게임이 될 것입니다 섹션 목록보기의 종류를 작성해야합니다.

목록보기 엔진이 배열에서 PER 개체를 생성하는 것이 문제입니다.

그래서 3 개의 GameSummary와 10 개의 게임을 배열에 포함하면 3 행만 생성됩니다!

어떻게해야합니까?

현재 사용자 지정 어댑터는 BaseAdapter 클래스에서 상속받습니다.

+1

은 행의 수는 getCount 방법에 의해 제어된다. 그러나 당신은 당신이 expandableListView로부터 이익을 얻는 것처럼 보입니다. – mango

답변

2

이와 같이 expandableListView 및 customAdapter를 사용해야합니다.

@SuppressLint("ResourceAsColor") 
    public class ExpandableListAdapter extends BaseExpandableListAdapter { 


     private LayoutInflater inflater; 
     private ArrayList<GameSummary> mParent; 

    public ExpandableListAdapter(Context context, ArrayList<GameSummary> parent){ 
      this.mParent = parent; 
      this.inflater = LayoutInflater.from(context); 
     } 


     //counts the number of group/parent items so the list knows how many times calls getGroupView() method 
     public int getGroupCount() { 
      return mParent.size(); 
     } 

     //counts the number of children items so the list knows how many times calls getChildView() method 
     public int getChildrenCount(int i) { 
      return mParent.getGameList(i).size(); 
     } 

     //gets the title of each parent/group 
     public Object getGroup(int i) { 
      return mParent.getGameList(i).getTitle(); //game Title 
     } 

     //gets the name of each item 
     public Object getChild(int i, int i1) { 
      return mParent.getGameList(i); 
     } 

     public long getGroupId(int i) { 
      return i; 
     } 

     public long getChildId(int i, int i1) { 
      return i1; 
     } 

     public boolean hasStableIds() { 
      return true; 
     } 


     //in this method you must set the text to see the parent/group on the list 
     public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) { 

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

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


      //return the entire view 
      return view; 
     } 


     //in this method you must set the text to see the children on the list 
     public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) { 
      if (view == null) { 
       view = inflater.inflate(R.layout.expandable_listview_child_item, viewGroup,false); 
      } 

      TextView textView = (TextView) view.findViewById(R.id.list_item_text_child); 
      //"i" is the position of the parent/group in the list and 
      //"i1" is the position of the child 
      textView.setText(mParent.get(i).getGameList(i1)); 

      //return the entire view 
      return view; 
     } 

     public boolean isChildSelectable(int i, int i1) { 
      return true; 
     } 

및 클래스 : baseAdapter와

public class GameSummary 
{ 
String round; 
List<Game> gameList; 
} 
관련 문제