android - 通过单击 Recyclerview 项调用 SlidingUpPanelLayout
问题描述
我是新手并实现了一个在单击项目时androidstudio
调用的函数。喜欢这个gifslidinguppanellayout
recyclerview
这是我尝试过的:
binding
使用or构建一个方法findviewbyid
。但它失败了,因为我无法在recyerviewadapter
.- 用于
intent
切换activity
。但我无法使用slidinguppanellayout
.
同时,我找到了SlidingPaneLayout
可能有助于解决问题的解决方案,但我无法弄清楚如何在slidinguppanellayout
.
我找到的代码。来自安卓开发者
// A method on the Fragment that owns the SlidingPaneLayout,
// called by the adapter when an item is selected.
fun openDetails(itemId: Int) {
childFragmentManager.commit {
setReorderingAllowed(true)
replace<ItemFragment>(R.id.detail_container,
bundleOf("itemId" to itemId))
// If we're already open and the detail pane is visible,
// crossfade between the fragments.
if (binding.slidingPaneLayout.isOpen) {
setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
}
}
binding.slidingPaneLayout.open()
}
我已经尝试了 2 周,但一直失败。你能告诉我当像上面的 gif 那样点击项目slidinguppanellayout
时如何调用吗?recycerview
xml
代码
<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="bottom"
app:umanoPanelHeight="16dp"
app:umanoDragView="@id/main_layout">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/first_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="match_parent"
android:layout_height="430dp"
android:paddingBottom="15dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/slide_layout"
android:layout_width="match_parent"
android:layout_height="430dp"
android:background="#ffffff"/>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
recyclerview adapter
代码
class RecyclerViewAdapter(
val itemList: ArrayList<CoinList>,
val inflater: LayoutInflater
) : RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>(), Filterable {
private var searchList: ArrayList<CoinList>? = null
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val name: TextView
val count: TextView
init {
name = itemView.findViewById(R.id.coin_name)
count = itemView.findViewById(R.id.coin_count)
}
}
init {
this.searchList = itemList
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = inflater.inflate(R.layout.item_view, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.name.setText(itemList.get(position).name)
holder.count.setText(itemList.get(position).count)
holder.itemView.setOnClickListener {
}
}
override fun getItemCount(): Int {
return itemList.size
}
}
任何帮助,将不胜感激。谢谢 :)
解决方案
推荐阅读
- maven - Mule Munit 找不到 com.mulesoft.mule.distributions:mule-runtime-impl-bom:pom:4.2.0
- java - 无法在 Catalina 上设置 JAVA_HOME
- oracle-data-integrator - Windows 服务器上的 ODI 工作室
- r - 将日期范围扩大到每个实例有一行,同时考虑剂量频率
- json - 需要将数据类型转换为 json。尝试将 json.dumps、json.loads、chnges 转换为字符串而不是 json 类型
- encryption - 从 EWS 读取受 O365 保护的邮件?
- typescript - 使用动态字符串为允许的枚举值键入保护?
- bash - 用于备份过滤目录的 Shell 脚本
- android-studio - 落柱房间迁移android
- c++ - 通过辩论的区别