PopupWindow使用

PopupWindow

//布局使用弹出pop

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/bg_one"
android:layout_marginHorizontal="@dimen/dp_10"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
    android:layout_marginTop="@dimen/dp_20"
    android:id="@+id/pop_rlv_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:layout_marginTop="@dimen/dp_10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/wy" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/kz" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/qz" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/y1" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@mipmap/ddmy" />
</LinearLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/pop_rlv_2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/dp_20"/>

//点击弹出pop

 @OnClick({R.id.meun})
public void onClick(View v) {
switch (v.getId()) {
    default:
        break;
    case R.id.meun:
        View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.pop_itme, null);
        pop_rlv_1 = view.findViewById(R.id.pop_rlv_1);
        pop_rlv_2 = view.findViewById(R.id.pop_rlv_2);
      //显示一级条目
        pop_rlv_1.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false));
/调接口
        myOnePresenter = new MyOnePresenter(new setPop1());
        myOnePresenter.requestData();
        //调用适配器
        myOneAdapter = new MyOneAdapter(MainActivity.this);
        pop_rlv_1.setAdapter(myOneAdapter);

        //popupWindow展示
        PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
        popupWindow.showAsDropDown(meun, 0, 0);
        break;
}

//点击第一个条目请求第二个接口

myOneAdapter.setOnItmeListener(new MyOneAdapter.onItmeListener()   {
@Override
public void getHttpData(String position) {
    pop_rlv_2.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false));
    myTwoPresenter = new MyTwoPresenter(new setPop2());
    myTwoPresenter.requestData(App.firstCategoryId + "");
    myTwoAdapter = new MyTwoAdapter(MainActivity.this);
    pop_rlv_2.setAdapter(myTwoAdapter);
}

});
//二级列表

private class setPop2 implements DataCall {
@Override
public void seccer(Object o, Object... args) {
    Result<List<MyTwoBean>> twoList = (Result<List<MyTwoBean>>) o;
    myTwoAdapter.addALL(twoList.result);
    myTwoAdapter.notifyDataSetChanged();
    //点击第二个条目展示数据
    myTwoAdapter.setOnItmeListener(new MyTwoAdapter.onItmeListener() {
        @Override
        public void getHttpData(String position, String page, String count) {
            x_rvl.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
            mySsCxPresenter = new MySsCxPresenter(new setSs());
            mySsCxPresenter.requestData(App.categoryId, page, count);
            mySsCxAdapter = new MySsCxAdapter(MainActivity.this);
            x_rvl.setAdapter(mySsCxAdapter);
        }
    });
}

//接口回调

private onItmeListener onItmeListener;

public void setOnItmeListener(MyTwoAdapter.onItmeListener onItmeListener) {
this.onItmeListener = onItmeListener;

}

public interface onItmeListener {
void getHttpData(String position,String page,String count);

}
//点击条目使用接口回调

viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    App.categoryId = list.get(i).getId();
    if (onItmeListener != null) {
        onItmeListener.getHttpData(App.categoryId,1+"",5+"");
    }
}
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值