直播原始碼網站,實現對話方塊的左滑動刪除
阿新 • • 發佈:2021-12-22
直播原始碼網站,實現對話方塊的左滑動刪除的相關程式碼
在你專案的 build.gradle 新增:
implementation 'io.github.sakurajimamaii:VastSwipeListView:0.0.1'
快速開始
在你的佈局中新增 VastSwipeListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SlideActivity">
<com.gcode.vastswipelayout.view.VastSwipeListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"/>
</LinearLayout>
使用 VastSwipeMenuItem 來定義你的選單項,呼叫 VastSwipeMenuMgr 內的方法將選單項新增進去
我們這裡以定義撤銷項舉例
val deleteItem = VastSwipeMenuItem(this@SlideActivity)
deleteItem.setBackgroundByColorInt(0xFF1e90ff)
deleteItem.setTitleByString("撤銷")
deleteItem.setTitleColorByColorInt(Color.WHITE)
deleteItem.setIconByResId(R.drawable.ic_delete)
deleteItem.setClickEvent { item: VastSwipeMenuItem, position: Int ->
run {
Toast.makeText(this@SlideActivity, "${item.title} $position", Toast.LENGTH_SHORT)
.show()
}
}
swipeMenuMgr.addLeftMenuItem(deleteItem)
準備列表項資料的adapter
val listViewAdapter = ListViewAdapter(this, R.layout.listview_item, lists)
將設定好的 VastSwipeMenuMgr 和列表項 Adapter 傳給 VastSwipeListView
vastSwipeListView.setSwipeMenuMgr(swipeMenuMgr)
vastSwipeListView.adapter = listViewAdapter
vastSwipeListView.onItemClickListener =
AdapterView.OnItemClickListener { _, _, arg2, _ ->
Toast.makeText(
context,
"位置 " + arg2 + " >>> value:" + lists[arg2],
Toast.LENGTH_SHORT
).show()
}
以上就是直播原始碼網站,實現對話方塊的左滑動刪除的相關程式碼, 更多內容歡迎關注之後的文章