Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
SuZhouAvp
Commits
1441e432
Commit
1441e432
authored
Sep 11, 2025
by
罗小雨
Browse files
完善车辆选择弹窗
parent
c47f24d6
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/cavphmi/ui/MainActivity.kt
View file @
1441e432
...
...
@@ -2,6 +2,7 @@ package com.sd.cavphmi.ui
import
android.view.KeyEvent
import
android.widget.RelativeLayout
import
android.widget.Toast
import
androidx.activity.viewModels
import
androidx.lifecycle.ViewModelProvider
import
com.sd.cavphmi.BR
...
...
@@ -12,7 +13,7 @@ import com.sd.cavphmi.databinding.ActivityMainBinding
import
com.sd.cavphmi.intfaces.OnConCan
import
com.sd.cavphmi.ui.fragment.CarPanelFragment
import
com.sd.cavphmi.ui.fragment.ExoPlayFragment
import
com.sd.cavphmi.ui.view.CustomDialog
import
com.sd.cavphmi.ui.view.Custom
List
Dialog
import
com.sd.cavphmi.utils.DisplayUtil
import
com.sd.cavphmi.viewmodels.MainVm
import
com.sd.cavphmi.viewmodels.MockVM
...
...
@@ -25,7 +26,8 @@ import dagger.hilt.android.AndroidEntryPoint
* @constructor Create empty Main activity
*/
@AndroidEntryPoint
class
MainActivity
:
BaseActivity
<
ActivityMainBinding
,
MyBaseViewModel
>()
{
class
MainActivity
:
BaseActivity
<
ActivityMainBinding
,
MyBaseViewModel
>(),
CustomListDialog
.
OnItemClickListener
{
override
fun
getStatuBarColor
():
Int
{
return
-
1
...
...
@@ -108,9 +110,9 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
}
//模拟选择车辆
binding
.
btSetcar
.
setOnClickListener
{
val
dialog
=
CustomDialog
(
this
)
var
list
=
listOf
(
"skywell.1ggvlp16.car10"
,
"skywell.1ggvlp16.car8"
)
dialog
.
setData
(
list
)
val
dialog
=
CustomListDialog
(
this
,
"选择车辆"
,
list
)
dialog
.
setOnItemClickListener
(
this
)
dialog
.
show
()
}
}
...
...
@@ -190,6 +192,10 @@ class MainActivity : BaseActivity<ActivityMainBinding, MyBaseViewModel>() {
return
super
.
dispatchKeyEvent
(
event
)
}
}
override
fun
onItemClick
(
position
:
Int
,
selectedItem
:
String
)
{
Toast
.
makeText
(
this
,
"点击了第${position + 1}项: $selectedItem"
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
/* https://docs.qq.com/sheet/DVWdOYXZXdVVrQWts?tab=xxmysv socket文档
...
...
app/src/main/java/com/sd/cavphmi/ui/view/CustomDialog.kt
deleted
100644 → 0
View file @
c47f24d6
package
com.sd.cavphmi.ui.view
import
android.app.Dialog
import
android.content.Context
import
android.graphics.Color
import
android.graphics.drawable.ColorDrawable
import
android.view.LayoutInflater
import
android.view.Window
import
android.view.WindowManager
import
android.widget.LinearLayout
import
android.widget.TextView
import
com.sd.cavphmi.R
class
CustomDialog
(
context
:
Context
)
:
Dialog
(
context
)
{
lateinit
var
list
:
List
<
String
>
init
{
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
)
window
?.
setBackgroundDrawable
(
ColorDrawable
(
Color
.
TRANSPARENT
))
// 设置窗口背景透明[6](@ref)
setContentView
(
R
.
layout
.
dialog_custom
)
setCancelable
(
false
)
setCanceledOnTouchOutside
(
false
)
window
?.
setLayout
(
WindowManager
.
LayoutParams
.
MATCH_PARENT
,
WindowManager
.
LayoutParams
.
WRAP_CONTENT
)
val
btnCancel
=
findViewById
<
TextView
>(
R
.
id
.
tv_cancle
)
val
llCar
=
findViewById
<
LinearLayout
>(
R
.
id
.
ll_car
)
for
(
item
in
list
){
var
carView
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
item_car
,
null
)
val
tv_car
=
carView
.
findViewById
<
TextView
>(
R
.
id
.
tv_car
)
tv_car
.
setOnClickListener
{
dismiss
()
}
llCar
.
addView
(
carView
)
}
btnCancel
.
setOnClickListener
{
dismiss
()
}
// 点击取消按钮关闭对话框
}
fun
setData
(
data
:
List
<
String
>){
this
.
list
=
data
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/ui/view/CustomListDialog.kt
0 → 100644
View file @
1441e432
package
com.sd.cavphmi.ui.view
import
android.app.Dialog
import
android.content.Context
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.LinearLayout
import
android.widget.TextView
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
com.sd.cavphmi.R
class
CustomListDialog
(
context
:
Context
,
private
val
title
:
String
,
private
val
dataList
:
List
<
String
>
)
:
Dialog
(
context
)
{
interface
OnItemClickListener
{
fun
onItemClick
(
position
:
Int
,
selectedItem
:
String
)
}
private
var
itemClickListener
:
OnItemClickListener
?
=
null
// 3. 设置监听器的方法
fun
setOnItemClickListener
(
listener
:
OnItemClickListener
)
{
this
.
itemClickListener
=
listener
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
dialog_custom
)
window
?.
setBackgroundDrawableResource
(
android
.
R
.
color
.
transparent
)
window
?.
setLayout
(
LinearLayout
.
LayoutParams
.
MATCH_PARENT
,
LinearLayout
.
LayoutParams
.
WRAP_CONTENT
)
findViewById
<
TextView
>(
R
.
id
.
title
).
text
=
title
findViewById
<
TextView
>(
R
.
id
.
tv_cancle
).
setOnClickListener
{
dismiss
()
}
val
recyclerView
=
findViewById
<
RecyclerView
>(
R
.
id
.
recyclerView
)
recyclerView
.
layoutManager
=
LinearLayoutManager
(
context
)
val
adapter
=
SimpleAdapter
(
dataList
)
{
position
,
item
->
itemClickListener
?.
onItemClick
(
position
,
item
)
dismiss
()
}
recyclerView
.
adapter
=
adapter
}
class
SimpleAdapter
(
private
val
items
:
List
<
String
>,
private
val
onItemClick
:
(
Int
,
String
)
->
Unit
)
:
RecyclerView
.
Adapter
<
SimpleAdapter
.
ViewHolder
>()
{
inner
class
ViewHolder
(
val
view
:
View
)
:
RecyclerView
.
ViewHolder
(
view
)
override
fun
onCreateViewHolder
(
parent
:
ViewGroup
,
viewType
:
Int
):
ViewHolder
{
val
view
=
LayoutInflater
.
from
(
parent
.
context
)
.
inflate
(
R
.
layout
.
item_car
,
parent
,
false
)
return
ViewHolder
(
view
)
}
override
fun
onBindViewHolder
(
holder
:
ViewHolder
,
position
:
Int
)
{
val
textView
=
holder
.
view
.
findViewById
<
TextView
>(
R
.
id
.
tv_car
)
textView
.
text
=
items
[
position
]
textView
.
setOnClickListener
{
onItemClick
(
position
,
items
[
position
])
}
}
override
fun
getItemCount
()
=
items
.
size
}
}
\ No newline at end of file
app/src/main/res/drawable/shape_dialog_custom.xml
0 → 100644
View file @
1441e432
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
<corners
android:radius=
"16dp"
/>
<solid
android:color=
"@android:color/white"
/>
</shape>
\ No newline at end of file
app/src/main/res/layout/dialog_custom.xml
View file @
1441e432
...
...
@@ -6,52 +6,47 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<
androidx.cardview.widget.CardView
a
pp:cardCornerRadius=
"10dp
"
<
LinearLayout
a
ndroid:background=
"@drawable/shape_dialog_custom
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<LinearLayout
android:background=
"@color/white"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<RelativeLayout
android:paddingHorizontal=
"16dp"
android:paddingVertical=
"10dp"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<RelativeLayout
android:paddingHorizontal=
"16dp"
android:paddingVertical=
"10dp"
android:layout_width=
"match_parent"
<TextView
android:id=
"@+id/title"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"16sp"
android:textColor=
"@color/black"
android:text=
"选择车辆"
android:layout_centerInParent=
"true"
/>
<TextView
android:id=
"@+id/tv_cancle"
android:layout_centerVertical=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"取消"
android:textSize=
"14sp"
android:textColor=
"#555"
/>
</RelativeLayout>
android:textSize=
"16sp"
android:textColor=
"@color/black"
android:text=
"选择车辆"
android:layout_centerInParent=
"true"
/>
<LinearLayout
android:id=
"@+id/ll_car"
android:layout_width=
"match_parent"
<TextView
android:id=
"@+id/tv_cancle"
android:layout_centerVertical=
"true"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:text=
"取消"
android:textSize=
"14sp"
android:textColor=
"#555"
/>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@+id/recyclerView"
android:overScrollMode=
"never"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment