美文网首页
2018-07-18

2018-07-18

作者: 蓦然恨 | 来源:发表于2018-07-18 12:16 被阅读0次

PopupWindow在recyclerviewAdapter 中粗略写法:
xml图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="40dp"
    android:layout_height="55dp"
    android:background="#ffffff"
    android:gravity="center"
    android:elevation="4dp"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15dp"
        android:textColor="#006CBE"
        android:id="@+id/pop_man"
        android:text="男"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="#D1EEEE"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15dp"
        android:textColor="#006CBE"
        android:id="@+id/pop_woman"
        android:text="女"/>

</LinearLayout>

 override fun onBindViewHolder(holder:RecyclerView.ViewHolder, position: Int) {
        when{
            getItemViewType(position)==WORK_TYPE -> {
                holder as WorkViewHolder
                holder.text1.text = list?.get(position)?.getText1()
                holder.text2.text = list?.get(position)?.getText2()
            }
               when(position) {
                      2->{
                          contextView = LayoutInflater.from(context).inflate(R.layout.work_sex_popupwindow,null,false)
                          popupwindow = PopupWindow().apply {
                              contentView = contextView
                              height = ViewGroup.LayoutParams.WRAP_CONTENT
                              setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                              width = 80
                              isFocusable = true
                             isOutsideTouchable = true
                          holder.text2.setOnClickListener {
                               popupwindow.showAsDropDown(holder.text2,0,0)
                          }
                       contentView.findViewById<TextView>(R.id.pop_man).setOnClickListener {
                              holder.text2.setText("男")
                              popupwindow.dismiss()
                         }
                             contentView.findViewById<TextView>(R.id.pop_woman).setOnClickListener {
                                 holder.text2.setText("女")
                                 popupwindow.dismiss()
                              }
                         }
                     }else->{ }
               }
            getItemViewType(position)==HEAD_TYPE -> {
                holder as headViewHolder
                holder.image
            }
            else ->{
                holder as footViewHolder
            }
        }
     }

相关文章

网友评论

      本文标题:2018-07-18

      本文链接:https://www.haomeiwen.com/subject/qldopftx.html