栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

FilterPopupWindow

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

FilterPopupWindow

FilterPopupWindow.java
public class FilterPopupWindow extends PopupWindow {

    private Context context;
    private RecyclerView recyclerView;
    List mList;
    BaseQuickAdapter mAdapter;
;
    public FilterPopupWindow(Context context, @NotNull List list,RelativeLayout view,int spanCount,String textStr) {
        super(context);
        this.context = context;
        this.mList = list;
        initPPP(view,spanCount,textStr);
    }

    private OnFilterPopupWindowListener onFilterPopupWindowListener;
    public void setOnFilterPopupWindowListener(OnFilterPopupWindowListener onFilterPopupWindowListener) {
        this.onFilterPopupWindowListener = onFilterPopupWindowListener;
    }
    public interface OnFilterPopupWindowListener {
        void getText(String string,int i);
    }
    private void initPPP(RelativeLayout view,int spanCount,String textStr) {
        View inflate = View.inflate(context, R.layout.ppp_order_filter, null);
        mAdapter = new BaseQuickAdapter(R.layout.ppp_order_filter_child_item,mList){
            @Override
            protected void convert(BaseViewHolder helper, String item) {
                TextView titleTv = helper.getView(R.id.ppp_order_filter_child_item_title);
                titleTv.setGravity(Gravity.CENTER);
                if(textStr.equals(item)){
                    titleTv.setActivated(true);
                }
                titleTv.setText(item);
                titleTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String text = titleTv.getText().toString();
                        if (onFilterPopupWindowListener != null){
                            onFilterPopupWindowListener.getText(text,helper.getAdapterPosition());
                        }
                        dismiss();
                    }
                });
            }
        };
        recyclerView = inflate.findViewById(R.id.ppp_order_filter_recycler);
        recyclerView.setLayoutManager(new GridLayoutManager(context, spanCount));
        recyclerView.setAdapter(mAdapter);
        setWidth(view.getWidth()-10);
        setContentView(inflate);
        setFocusable(true);
        setTouchable(true);
        setOutsideTouchable(true);
        setBackgroundDrawable(new ColorDrawable());

    }
}
ppp_order_filter.xml



    
        
    

    



ppp_order_filter_child_item.xml


bg_order_filter_css.xml


    
        
            
            
            
        
    
    
        
            
            
            
        
    
bg_order_filter_text_css.xml



    
    

在activity里使用,radio是点击出现弹窗的控件,也可以是TextView或者其他,传入这个参数是为了做选中的效果。

FilterPopupWindow orderFilterPopupWindow ;
    private void setPopupWindow( List list1, RadioButton radio, int spanCount) {
        orderFilterPopupWindow = new FilterPopupWindow(this, list1, realFilter,spanCount,radio.getText().toString());
        orderFilterPopupWindow.showAsDropDown(realFilter);

        orderFilterPopupWindow.setOnFilterPopupWindowListener(new FilterPopupWindow.OnFilterPopupWindowListener() {
            @Override
            public void getText(String string, int position) {
                orderFilterPopupWindow.dismiss();
                if (string == null){
                    return;
                }
                
                }
                orderFilterPopupWindow.dismiss();
            }
        });
    }

效果图

选择前:

 选择后

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/995099.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号