Android 我在使用xml时遇到崩溃<;包括/>;科特林标签
我正在kotlin中编码,并在我的layout.xml中使用from,当我调用bottomsheet\u map布局的子项时,我的应用程序崩溃 我的父布局:Android 我在使用xml时遇到崩溃<;包括/>;科特林标签,android,xml,android-studio,kotlin,Android,Xml,Android Studio,Kotlin,我正在kotlin中编码,并在我的layout.xml中使用from,当我调用bottomsheet\u map布局的子项时,我的应用程序崩溃 我的父布局: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<include layout="@layout/bottomsheet_map" />
...
</androidx.constraintlayout.widget.ConstraintLayout>
注意:我不会使用findViewByID。没有findViewByID()调用点击动作布局是否有更好的解决方案
在
onViewCreated
而不是onCreateView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tap_action_layout.setOnClickListener { v: View? ->
//....
}
}
在
onViewCreated
而不是onCreateView
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tap_action_layout.setOnClickListener { v: View? ->
//....
}
}
您无法直接访问代码中包含的元素。您需要在包含其他布局的父布局上使用findviewbyid 例如:
您无法直接访问代码中包含的元素。您需要在包含其他布局的父布局上使用findviewbyid 例如:
您必须首先在xml布局中将android:id设置为include标签:
<include android:id="@+id/my_layout"
layout="@layout/bottomsheet_map" />
否则,如果不使用kotlin synthetic,则需要首先调用findViewById(R.id.top\u action\u layout)
:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
my_layout.findViewById(R.id.top_action_layout).setOnClickListener {
// do whatever you wanna do here..
}
}
您必须首先在xml布局中将android:id设置为include标签:
<include android:id="@+id/my_layout"
layout="@layout/bottomsheet_map" />
否则,如果不使用kotlin synthetic,则需要首先调用findViewById(R.id.top\u action\u layout)
:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
my_layout.findViewById(R.id.top_action_layout).setOnClickListener {
// do whatever you wanna do here..
}
}
我想
tap\u action\u layout
需要执行一个视图
试试这个
val view = inflater!!.inflate(R.layout.layout, container, false)
view.tap_action_layout.setOnClickListener { v: View? ->
//....
}
return view
这应该可以很好地工作。我想
点击操作布局
需要执行一个视图
试试这个
val view = inflater!!.inflate(R.layout.layout, container, false)
view.tap_action_layout.setOnClickListener { v: View? ->
//....
}
return view
这应该可以很好地工作。在xml布局中,需要将android:id设置为:
<include android:id="@+id/bottomsheet_map_layout"
layout="@layout/bottomsheet_map" />
在xml布局中,需要将android:id设置为:
<include android:id="@+id/bottomsheet_map_layout"
layout="@layout/bottomsheet_map" />
发布您的错误PLZ是否可以添加错误日志?如果使用findViewByID调用child,则没有问题。。。我不会使用findViewByID,因为我的孩子数非常多。发布您的错误请添加错误日志?如果使用findViewByID调用孩子,没有问题。。。我不会使用findViewByID,因为我的孩子数非常多
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
my_layout.top_action_layout.setOnClickListener {
// do whatever you wanna do here..
}
}