直播视频app源码,底部弹出的列表对话框实现的相关代码
1.activity_main.xml
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:textSize="30dp" />
<TextView
android:id="@+id/tv2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_weight="1.0"
android:gravity="right"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/tv1"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
2.MainActivity.kt
class MainActivity : AppCompatActivity() {
private var list: MutableList<Dict> = ArrayList()
private var x :Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
tv1.text = "宿舍";tv2.text = "小红"//默认
initDatas()
//点击底部弹出的列表对话框
ll.setOnClickListener {
for (i in 0 until list.size) {
if (tv2.text == list[i].dataName){//如果tv2.text是小红找到对应list的i的姓名
x = i;//i给x的赋值
break
}
}
//底部弹出的列表对话框
showBottomRadListDialog(tv1.text.toString(), list[x].dataValue, list as List<Dict>, object : OnResultCallback<String> {
//列表对话框被点击自己选择某一item数据
override fun onResult(t: Any) {
var dataValue :String = t.toString()
for (i in 0 until list.size){
if (dataValue == list[i].dataValue){
//dataValue对应的list[i].dataValue给tv2.text的赋值
tv2.text = list[i].dataName
break
}
}
}
})
}
}
//Dict实体类设置数据,可以看到这数据有规律
private fun initDatas() {
var sc = Dict("1", "4", "宿舍", "小红", "1");list.add(sc)
sc = Dict("2", "4", "宿舍", "小彬", "2");list.add(sc)
sc = Dict("3", "4", "宿舍", "小强", "3");list.add(sc)
sc = Dict("4", "4", "宿舍", "小华", "4");list.add(sc)
sc = Dict("5", "4", "宿舍", "小军", "5");list.add(sc)
sc = Dict("6", "4", "宿舍", "小文", "6");list.add(sc)
sc = Dict("7", "4", "宿舍", "小可", "7");list.add(sc)
sc = Dict("8", "4", "宿舍", "小进", "8");list.add(sc)
sc = Dict("9", "4", "宿舍", "小明", "9");list.add(sc)
sc = Dict("10", "4", "宿舍", "小一", "10");list.add(sc)
sc = Dict("11", "4", "宿舍", "小乐", "11");list.add(sc)
}
}
3.实体类Dict.kt
public class Dict {
private String id;//可以忽略
private String dataType;//可以忽略
private String dataTypeName;//表示“宿舍”两个字
private String dataName;//表示宿舍里每人的姓名
private String dataValue;//表示宿舍里人姓名排序
?4.DialogUtil.kt,底部弹出的列表对话框(单选)
fun showBottomRadListDialog(title:String?,selValue:String?,dictList:List<Dict>, callback: OnResultCallback<String>, defaultBackground:Boolean = true){
var dialog = AnyLayer.dialog()
.contentView(R.layout.dialog_list)//列表框布局
.gravity(Gravity.BOTTOM)
.animStyle(DialogLayer.AnimStyle.BOTTOM)
//使用默认的背景
if(defaultBackground){
dialog.backgroundDimDefault()
}
dialog.show()
dialog.getView<TextView>(R.id.tv_dialog_title).text = title?:""
var rv = dialog.getView<MaxHeightRecyclerView>(R.id.mRecyclerView)
//PhoneU:屏障像素获取手机大小(分辨率)
rv.setMaxHeight(PhoneU.getScreenPix(MyApplication.context)!!.heightPixels * 3 / 5 )
var selValue: String?= selValue
var mAdapter = RadListAdapter(selValue).apply{
setOnItemClickListener { _, _, position ->
var dict = getItem(position)
dict?.let {
var mValue = it.dataValue
if(mValue.equals(selValue)){
selValue = ""
}else{
selValue = mValue
}
setCheckSelValue(selValue)
}
}
}
rv.adapter = mAdapter
mAdapter.setList(dictList)
rv.scrollToPosition(mAdapter.getSelectIndex())
var fl = dialog.getView<FrameLayout>(R.id.fl_dialog_confirm)
fl.setOnClickListener {
dialog.dismiss()
selValue?.let { it1 -> callback.onResult(it1) }
}
}
以上就是 直播视频app源码,底部弹出的列表对话框实现的相关代码,更多内容欢迎关注之后的文章
原文:https://www.cnblogs.com/yunbaomengnan/p/15347788.html