Search in sources :

Example 1 with BaseExpandableListAdapter

use of android.widget.BaseExpandableListAdapter in project ExpandableListViewDemo by Qiaoxinghua.

the class MainActivity method initData.

/**
 * 设置ExpandableView适配器
 */
private void initData() {
    shopList = new ArrayList<>();
    // 购物车内商品数量
    int count = 0;
    for (int i = 0; i < 2; i++) {
        // 两个店铺
        Shop shop = new Shop();
        shop.setShopId("shop_id_" + i);
        shop.setShopName("shop_name_" + i);
        // 初始设置店铺不被选中
        shop.setShopSelect(false);
        List<Shop.Goods> goodsList = new ArrayList<>();
        for (int j = 0; j < 3; j++) {
            // 每个店铺三个商品
            Shop.Goods goods = new Shop.Goods();
            goods.setGoodsId("goods_id_" + i + j);
            goods.setGoodsName("goods_name_" + i + j);
            // 图片地址先不设置
            goods.setGoodsImgUrl("");
            goods.setGoodsPrice(10 + j + "");
            // 商品数量
            goods.setGoodsCount(2 + j);
            // 初始设置商品不被选中
            goods.setGoodsSelect(false);
            goodsList.add(goods);
            count++;
        }
        shop.setGoods(goodsList);
        shopList.add(shop);
    }
    tvTitle.setText("购物车(" + count + ")");
    baseExpandableListAdapter = new BaseExpandableListAdapter() {

        // 设置总得分组
        @Override
        public int getGroupCount() {
            return shopList.size();
        }

        // 设置每个分组有多少个小项
        @Override
        public int getChildrenCount(int groupPosition) {
            return shopList.get(groupPosition).getGoods().size();
        }

        @Override
        public Object getGroup(int groupPosition) {
            return shopList.get(groupPosition);
        }

        @Override
        public Object getChild(int groupPosition, int childPosition) {
            return shopList.get(groupPosition).getGoods().get(childPosition);
        }

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

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

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

        // 设置组的界面
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
            View view = View.inflate(MainActivity.this, R.layout.group_view, null);
            TextView tvGroupName = (TextView) view.findViewById(R.id.tv_group_name);
            RelativeLayout rlGroup = (RelativeLayout) view.findViewById(R.id.rl_group);
            final ImageView ivGroupCheck = (ImageView) view.findViewById(R.id.iv_group_icon);
            if (isExpanded) {
                ivGroupCheck.setImageResource(R.mipmap.ic_uncheck);
            } else {
                ivGroupCheck.setImageResource(R.mipmap.ic_uncheck);
            }
            // 绑定数据
            final Shop shop = shopList.get(groupPosition);
            // 店铺名称
            String shopName = shop.getShopName();
            tvGroupName.setText(shopName);
            if (shop.getGoods().size() == 0) {
                rlGroup.setVisibility(View.GONE);
            } else {
                rlGroup.setVisibility(View.VISIBLE);
            }
            if (shop.isShopSelect()) {
                // 设置当前店铺图标为选中状态
                ivGroupCheck.setImageResource(R.mipmap.ic_checked);
            } else {
                // 设置为未选中状态
                ivGroupCheck.setImageResource(R.mipmap.ic_uncheck);
            }
            // 控制全选按钮的状态
            ivAllCheck.setImageResource(R.mipmap.ic_checked);
            ivAllEditCheck.setImageResource(R.mipmap.ic_checked);
            for (int i = 0; i < shopList.size(); i++) {
                if (!shopList.get(i).isShopSelect()) {
                    // 有一个店铺未选中,则全选按钮也设置未选中
                    ivAllCheck.setImageResource(R.mipmap.ic_uncheck);
                    ivAllEditCheck.setImageResource(R.mipmap.ic_uncheck);
                }
            }
            ivGroupCheck.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (shop.isShopSelect()) {
                        // 当前已选中,设置为未选中状态
                        shop.setShopSelect(false);
                        ivGroupCheck.setImageResource(R.mipmap.ic_uncheck);
                        // 并把当前店铺下的所有商品全部设置为未选中状态
                        List<Shop.Goods> goods = shop.getGoods();
                        for (Shop.Goods good : goods) {
                            good.setGoodsSelect(false);
                        }
                        // 刷新一下
                        notifyDataSetChanged();
                    } else {
                        // 当前未选中,设置为选中状态
                        shop.setShopSelect(true);
                        ivGroupCheck.setImageResource(R.mipmap.ic_checked);
                        // 并把当前店铺下的所有商品全部设置为选中状态
                        List<Shop.Goods> goods = shop.getGoods();
                        for (Shop.Goods good : goods) {
                            good.setGoodsSelect(true);
                        }
                        // 刷新一下
                        notifyDataSetChanged();
                    }
                }
            });
            return view;
        }

        // 设置组里面的项的界面
        @Override
        public View getChildView(final int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            View view = View.inflate(MainActivity.this, R.layout.child_view, null);
            final ImageView ivChildCheck = (ImageView) view.findViewById(R.id.iv_child_icon);
            final TextView tvChildName = (TextView) view.findViewById(R.id.tv_child_name);
            final TextView tvChildPrice = (TextView) view.findViewById(R.id.tv_child_price);
            final TextView tvChildNum = (TextView) view.findViewById(R.id.tv_child_num);
            final TextView tvMinus = (TextView) view.findViewById(R.id.tv_minus);
            final TextView tvPlus = (TextView) view.findViewById(R.id.tv_plus);
            final View divider = view.findViewById(R.id.divider);
            final List<Shop.Goods> goodsList = shopList.get(groupPosition).getGoods();
            final Shop.Goods goods = goodsList.get(childPosition);
            tvChildPrice.setText("¥" + goods.getGoodsPrice());
            tvChildName.setText(goods.getGoodsName());
            tvChildNum.setText(String.valueOf(goods.getGoodsCount()));
            calculate();
            if (childPosition == goodsList.size() - 1) {
                divider.setVisibility(View.VISIBLE);
            } else {
                divider.setVisibility(View.GONE);
            }
            if (goods.isGoodsSelect()) {
                // 设置当前店铺图标为选中状态
                ivChildCheck.setImageResource(R.mipmap.ic_checked);
            } else {
                // 设置为未选中状态
                ivChildCheck.setImageResource(R.mipmap.ic_uncheck);
            }
            ivChildCheck.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (goods.isGoodsSelect()) {
                        // 设置当前店铺图标为未选中状态
                        ivChildCheck.setImageResource(R.mipmap.ic_uncheck);
                        // 并把当前商品的设置为未选中
                        goods.setGoodsSelect(false);
                        // 当前商品对应的店铺也设置为未选中
                        shopList.get(groupPosition).setShopSelect(false);
                    } else {
                        // 设置为选中状态
                        ivChildCheck.setImageResource(R.mipmap.ic_checked);
                        // 并把当前商品的设置为选中
                        goods.setGoodsSelect(true);
                        // 先设置店铺选中
                        shopList.get(groupPosition).setShopSelect(true);
                        for (int i = 0; i < goodsList.size(); i++) {
                            if (!goodsList.get(i).isGoodsSelect()) {
                                // 如果有一个商品未选中就设置店铺未选中
                                shopList.get(groupPosition).setShopSelect(false);
                            }
                        }
                    }
                    // 刷新一下
                    notifyDataSetChanged();
                }
            });
            // 减按钮
            tvMinus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int goodsCount = goods.getGoodsCount();
                    if (goods.getGoodsCount() > 1) {
                        goods.setGoodsCount(goodsCount - 1);
                    } else {
                        Toast.makeText(MainActivity.this, "商品数量不能为0", Toast.LENGTH_SHORT).show();
                    }
                    tvChildNum.setText(String.valueOf(goods.getGoodsCount()));
                    baseExpandableListAdapter.notifyDataSetChanged();
                }
            });
            // 加按钮
            tvPlus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    int goodsCount = goods.getGoodsCount();
                    goods.setGoodsCount(goodsCount + 1);
                    tvChildNum.setText(String.valueOf(goods.getGoodsCount()));
                    baseExpandableListAdapter.notifyDataSetChanged();
                }
            });
            return view;
        }

        // 设置小项是否可以点击  一般设置都是可以点击
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
        }
    };
    elv.setAdapter(baseExpandableListAdapter);
    /**
     * 展开所有的组
     */
    for (int i = 0; i < 2; i++) {
        elv.expandGroup(i);
    }
}
Also used : BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ExpandableListView(android.widget.ExpandableListView) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) ImageView(android.widget.ImageView)

Example 2 with BaseExpandableListAdapter

use of android.widget.BaseExpandableListAdapter in project devbricks by dailystudio.

the class AbsExpandableListAdapterFragment method onGroupClick.

@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
    if (mOnListItemSelectedListener != null) {
        final BaseExpandableListAdapter adapter = getAdapter();
        if (adapter == null) {
            return false;
        }
        Object group = adapter.getGroup(groupPosition);
        mOnListItemSelectedListener.onListGroupSelected(group);
        return true;
    }
    return false;
}
Also used : BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter)

Example 3 with BaseExpandableListAdapter

use of android.widget.BaseExpandableListAdapter in project WordPress-Android by wordpress-mobile.

the class StatsAuthorsFragment method updateUI.

@Override
protected void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (!hasAuthors()) {
        showHideNoResultsUI(true);
        return;
    }
    BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), mAuthors.getAuthors());
    StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList());
    showHideNoResultsUI(false);
}
Also used : BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter)

Example 4 with BaseExpandableListAdapter

use of android.widget.BaseExpandableListAdapter in project WordPress-Android by wordpress-mobile.

the class StatsClicksFragment method updateUI.

@Override
protected void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (hasClicks()) {
        BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), mClicks.getClickGroups());
        StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList());
        showHideNoResultsUI(false);
    } else {
        showHideNoResultsUI(true);
    }
}
Also used : BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter)

Example 5 with BaseExpandableListAdapter

use of android.widget.BaseExpandableListAdapter in project WordPress-Android by wordpress-mobile.

the class StatsReferrersFragment method updateUI.

@Override
protected void updateUI() {
    if (!isAdded()) {
        return;
    }
    if (hasReferrers()) {
        BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), getReferrersGroups());
        StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList());
        showHideNoResultsUI(false);
    } else {
        showHideNoResultsUI(true);
    }
}
Also used : BaseExpandableListAdapter(android.widget.BaseExpandableListAdapter)

Aggregations

BaseExpandableListAdapter (android.widget.BaseExpandableListAdapter)8 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 AdapterView (android.widget.AdapterView)2 ExpandableListView (android.widget.ExpandableListView)2 AbsListView (android.widget.AbsListView)1 ImageView (android.widget.ImageView)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 AQuery (com.androidquery.AQuery)1 Photo (com.androidquery.test.image.ImageLoadingList4Activity.Photo)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1