0

次のような拡張可能なリストビュー コードがあり、正常に動作します。

public class CategoriesFragment extends Fragment implements OnChildClickListener, OnGroupClickListener{
    private static final String CAT_ID = "cat_id";
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.categories, null);
        ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.expandableListView1);
        elv.setOnGroupClickListener(this);
        elv.setOnChildClickListener(this);
        elv.setAdapter(new SavedTabsListAdapter());
        return v;
    }

    public class SavedTabsListAdapter extends BaseExpandableListAdapter {

        private String[] groups = { "Men", "Women", "Kids"};

        private String[][] children = {
            { "Accessories", "Jackets", "Jeans", "Knitwear"},
            { "Dresses", "Lingerie", "Maternity clothes"},
            { "Accessories", "Baby", "Kid's Shoes"}
        };

        int[][] cat_images = new int[][] {
                {R.drawable.bath_body_sales, R.drawable.bath_body_sales, R.drawable.bath_body_sales},
                {R.drawable.beauty_sales, R.drawable.beauty_sales, R.drawable.beauty_sales},
                {R.drawable.hair_products_sales, R.drawable.hair_products_sales, R.drawable.hair_products_sales}
                };

        @Override
        public int getGroupCount() {
            return groups.length;
        }

        @Override
        public int getChildrenCount(int i) {
            return children[i].length;
        }

        public int getImageCount(int j) {
            return cat_images[j].length;
        }

        @Override
        public Object getGroup(int i) {
            return groups[i];
        }

        @Override
        public Object getChild(int i, int i1) {
            return children[i][i1];
        }

        public Object getImage(int j, int j1) {
            return cat_images[j][j1];
        }

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

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

        public long getImageId(int j, int j1) {
            return j1;
        }

        @Override
        public boolean hasStableIds() {
            return true;
        }

        @Override
        public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
            TextView textView = new TextView(CategoriesFragment.this.getActivity());
            textView.setText(getGroup(i).toString());
            textView.setPadding(60, 15, 15, 15);
            textView.setTextSize(20);
            //textView.setTextColor(color.black);
            textView.setBackgroundColor(color.darker_gray);
            return textView;
        }

        @Override
        public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
            TextView textView = new TextView(CategoriesFragment.this.getActivity());
            //ImageView imageView = new ImageView(CategoriesFragment.this.getActivity());
            //imageView.setImageResource(getImage(i, i1));
            textView.setText(getChild(i, i1).toString());
            textView.setPadding(70, 15, 15, 15);
            textView.setTextSize(18);
            return textView;
        }

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

    Intent k;

    @Override
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
            long id) {
        return false;
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        return false;
    }
}

今、ドローアブルから子に画像を実装しようとしましたが、うまくいきませんでした。私を助けてください、私はそれを修正するために数時間を費やしています.

4

0 に答える 0