0

ArrayList をメンバーとして含むカスタム リストビュー アダプターがあります。

各ゲームはラウンドに属します。つまり:

public class GameSummary
{
 String round;
 Game game;
}

実際には、セクション リスト ビューのようなものを作成する必要があります。これは、ラウンドがヘッダーになり、その下のゲームになります。

問題は、リストビュー エンジンが配列内に行 PER オブジェクトを生成することです。

したがって、配列に 3 つの GameSummary と 10 のゲームがある場合、生成されるのは 3 行だけです!

私は何をすべきか ?

現在のカスタム アダプターは BaseAdapter クラスから継承されます。

4

1 に答える 1

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;
        }

そしてあなたのクラス:

public class GameSummary
{
 String round;
 List<Game> gameList;
}
于 2012-12-01T16:31:30.597 に答える