当我们点击相应的项目时,如何在recyclerview项目的顶部显示弹出窗口

问题描述 投票:0回答:1

这是必需的屏幕设计:

here

根据上面的截图,我需要设计布局:当我点击recyclerview项目行的添加按钮时,添加需要显示的选项。

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cell"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorLightWhite">


    <LinearLayout
        android:id="@+id/ll_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:visibility="visible"
        android:layout_marginRight="@dimen/default_margin"
        android:layout_marginLeft="@dimen/default_margin"
        android:layout_marginTop="@dimen/default_margin"
        android:layout_marginBottom="@dimen/default_margin"
        android:weightSum="100">
        <EditText
            android:id="@+id/et_add_member"
            android:layout_width="wrap_content"
            android:layout_weight="95"
            android:layout_height="42dp"
            android:padding="@dimen/padding_8"
            android:hint="Person"
            android:background="@drawable/edit_box"/>
        <ImageView
            android:id="@+id/iv_addMember"
            android:layout_width="wrap_content"
            android:layout_height="25dp"
            android:layout_gravity="center"
            android:layout_marginLeft="@dimen/default_margin"
            android:layout_centerVertical="true"
            android:layout_weight="5"
            android:src="@drawable/add_x" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/include_add"
        android:layout_width="210dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ll_main"
        android:layout_alignTop="@+id/ll_main"
        android:layout_marginTop="35dp"
        android:layout_marginRight="@dimen/margin_10"
        android:gravity="center"
        android:layout_alignParentRight="true"
        android:orientation="vertical"
        android:visibility="gone">

        <include layout="@layout/include_members" />
    </LinearLayout>

</RelativeLayout>

这是显示弹出窗口的适配器代码:

holder.ivAddMember.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                holder.include_add.setVisibility(View.VISIBLE);
            }
        });

include_add LinearLayout是pop代码,但是我无法使用此代码获得确切的UI。

任何人都可以建议我如何在相应的项目点击之上显示pop,如何关闭以前点击项目位置和弹出设计的弹出窗口。

java android recycler-adapter
1个回答
2
投票

您必须在res文件夹中的菜单下创建xml文件,然后按下面的功能显示所需位置的弹出窗口

public void showPopup() {
    PopupMenu popup = new PopupMenu(context, <PASS ID WHERE YOU WISH TO SHOW POPUP>);
    popup.getMenuInflater().inflate(R.menu.menu_option, popup.getMenu());
    Object menuHelper;
    Class[] argTypes;
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.member:
                    // call member class or function here
                    return true;
                case R.id.guest:
                    // call Guest class or function here
                    return true;
                case R.id.my_buddies:
                    // call My Buddies class or function here
                    return true;
            }
            return true;
        }
    });
    popup.show();
}

希望你能理解。

© www.soinside.com 2019 - 2024. All rights reserved.