PopWindow弹框三级列表

public class MainActivity extends AppCompatActivity implements Contract.Iview {

private Presenter presenter;
private RecyclerView recycler_frist;
private SouView sou_view;
private ImageView image_list;
private RecyclerView recycler_second;
private LayoutInflater view;
private RecyclerView recycler_view;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sou_view = findViewById(R.id.sou_view);
    image_list = sou_view.findViewById(R.id.image_list);
    presenter = new Presenter();
    presenter.attch(this);
    image_list.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            presenter.show(Api_URL.SHOW_URL);
        }
    });
    recycler_view = findViewById(R.id.recycler_view);
}

@Override
public void getRequest(String data) {
    view = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    View inflate = view.inflate(R.layout.pop_first,null);
    recycler_frist = inflate.findViewById(R.id.recycler_frist);
    Gson gson = new Gson();
    ShowBean showBean = gson.fromJson(data, ShowBean.class);
    final List<ShowBean.ResultBean> result = showBean.getResult();
    ShowAdapter showAdapter = new ShowAdapter(result, this);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recycler_frist.setLayoutManager(linearLayoutManager);
    recycler_frist.setAdapter(showAdapter);
    showAdapter.setOnclik(new ShowAdapter.OnClick() {
        @Override
        public void onClick(int i) {
            String id = result.get(i).getId();
            presenter.showTow(Api_URL.SHOW2_URL+"?firstCategoryId="+id);
        }
    });

    PopupWindow popupWindow = new PopupWindow(inflate, ActionBar.LayoutParams.FILL_PARENT,
            ActionBar.LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    //设置颜色
    ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
    popupWindow.setBackgroundDrawable(colorDrawable);
    popupWindow.showAsDropDown(image_list);
}

@Override
public void getTowRequest(String data) {
    View inflate1 = view.inflate(R.layout.pop_second,null);
    recycler_second = inflate1.findViewById(R.id.recycler_second);
    Gson gson = new Gson();
    ShowBean showBean = gson.fromJson(data, ShowBean.class);
    final List<ShowBean.ResultBean> result = showBean.getResult();
    ShowAdapter showAdapter = new ShowAdapter(result, this);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recycler_second.setLayoutManager(linearLayoutManager);
    recycler_second.setAdapter(showAdapter);
    showAdapter.setOnclik(new ShowAdapter.OnClick() {
        @Override
        public void onClick(int i) {
            String id = result.get(i).getId();
            presenter.showThree(Api_URL.SHOW3_URL+"?categoryId="+id+"&page="+1+"&count="+5);
        }
    });
    PopupWindow popupWindow = new PopupWindow(inflate1, ActionBar.LayoutParams.FILL_PARENT,
            ActionBar.LayoutParams.WRAP_CONTENT);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    //设置颜色
    ColorDrawable colorDrawable = new ColorDrawable((Color.GRAY));
    popupWindow.setBackgroundDrawable(colorDrawable);
    popupWindow.showAsDropDown(image_list,50,50);
}

@Override
public void getThreeRequest(String data) {
    Gson gson = new Gson();
    ListBean listBean = gson.fromJson(data, ListBean.class);
    List<ListBean.ResultBean> result = listBean.getResult();
    ListAdapter listAdapter = new ListAdapter(result, this);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 2);
    recycler_view.setLayoutManager(gridLayoutManager);
    recycler_view.setAdapter(listAdapter);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    presenter.detch();
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,实现这个功能,您需要使用 PopupWindow 和 ListView 一起来实现。以下是大致的实现步骤: 1. 创建一个布局文件,包含三个 ListView,分别用于展示省、市、县的列表项。 2. 在代码中,创建一个 PopupWindow 对象,并设置其宽度和高度。 3. 将布局文件加载到 PopupWindow 中,并设置其可以获得焦点和触摸事件。 4. 分别为三个 ListView 设置适配器,并初始化省级数据。 5. 为省级 ListView 设置点击事件,当点击一个省份时,根据其对应的城市数据更新城市列表,并将县级列表数据清空。 6. 为城市级 ListView 设置点击事件,当点击一个城市时,根据其对应的县级数据更新县级列表。 7. 点击县级列表中的某一项时,选定该项,并将选定的省、市、县数据返回给上层 Activity。 具体实现细节可以参考以下代码示例: ``` // 创建 PopupWindow 对象 PopupWindow popupWindow = new PopupWindow(context); // 加载布局文件 View contentView = LayoutInflater.from(context).inflate(R.layout.popupwindow_layout, null); popupWindow.setContentView(contentView); // 设置 PopupWindow 宽度和高度 popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); // 设置 PopupWindow 可以获得焦点和触摸事件 popupWindow.setFocusable(true); popupWindow.setTouchable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); // 获取省、市、县的 ListView ListView provinceList = contentView.findViewById(R.id.province_list); ListView cityList = contentView.findViewById(R.id.city_list); ListView countyList = contentView.findViewById(R.id.county_list); // 为省、市、县的 ListView 设置适配器 provinceList.setAdapter(provinceAdapter); cityList.setAdapter(cityAdapter); countyList.setAdapter(countyAdapter); // 初始化省级数据 provinceList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 根据点击的省份更新城市列表 cityAdapter.updateData(provinceData.get(position).getCities()); // 将县级列表数据清空 countyAdapter.clearData(); } }); // 更新县级列表数据 cityList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 根据点击的城市更新县级列表 countyAdapter.updateData(cityData.get(position).getCounties()); } }); // 点击县级列表中的某一项时,选定该项,并将选定的省、市、县数据返回给上层 Activity countyList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // 获取选定的省份、城市、县级数据 String province = provinceData.get(provinceList.getSelectedItemPosition()).getName(); String city = cityData.get(cityList.getSelectedItemPosition()).getName(); String county = countyData.get(position).getName(); // 将数据返回给上层 Activity if (listener != null) { listener.onSelected(province, city, county); } // 关闭 PopupWindow popupWindow.dismiss(); } }); // 显示 PopupWindow popupWindow.showAtLocation(parentView, Gravity.BOTTOM, 0, 0); ``` 其中,provinceAdapter、cityAdapter、countyAdapter 分别为省、市、县的适配器,provinceData、cityData、countyData 分别为省、市、县的数据列表。listener 为选定省、市、县后的回调接口,用于将选定的数据返回给上层 Activity。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值