安卓淘宝城市选择编写,弹框展示

-

淘宝城市选择编写

在这里插入图片描述

代码详细如下:主要逻辑内容在这个类中AreaSelectorDialog.class

布局文件:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    android:id="@+id/rlTopTip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="配送至"
        android:layout_centerInParent="true"
        android:textSize="@dimen/text_size_16"
        android:textColor="@color/text_color_light"
        android:layout_margin="@dimen/space_10"/>

    <ImageView
        android:id="@+id/ivAreaClose"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/location_close_dia"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:padding="@dimen/space_10"/>
</RelativeLayout>

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/background_input_normal"
    app:tabTextColor="@color/text_color_light"
    app:tabSelectedTextColor="@color/text_color_light"
    app:tabMode="scrollable"
    app:tabIndicatorColor="@color/color_orange"
    >
    <android.support.design.widget.TabItem
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="请选择"
        />

</android.support.design.widget.TabLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="@dimen/space_20"/>

TabLayout是动态添加和减少的

  //添加一个条目--->请选择前面一个--->tab总数-2
    private void addItem(int position) {
        TabLayout.Tab tab = tab_layout.newTab();
        tab.setTag(listBeans.get(position));
        tab.setText(listBeans.get(position).getName());
        TLog.INSTANCE.i("加之前tab的个数" + tab_layout.getTabCount());
        tab_layout.addTab(tab, tab_layout.getTabCount() - 1);
        TLog.INSTANCE.i("加之后tab的个数" + tab_layout.getTabCount());
        getAreaList(listBeans.get(position), false);
        setTabSelect();

    }
tab_layout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() != tab_layout.getTabCount() - 1) {
                    if (tab.getTag() == null) {
                        getAreaList(null, false);
                    } else {
                        //获取父级列表
                        getAreaList((AddressAreaEntity.ListBean) tab.getTag(), true);
                    }
                }
                //点击请选择,并且条目大于一个
                else if (tab_layout.getTabCount() > 1) {
                    getAreaList((AddressAreaEntity.ListBean) tab_layout.getTabAt(tab_layout.getTabCount() - 2).getTag(), false);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        ivAreaClose.setOnClickListener(v -> dismiss());
    }

recycleview是动态显示城市列表,由接口控制,及上一级城市code

代码地址:https://github.com/1136346879/picture_dx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值