Fragment / Kotin中的数据绑定

问题描述 投票:0回答:1

fragmentOne.kt



import android.icu.lang.UCharacter.GraphemeClusterBreak.T
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.fragment.findNavController

import androidx.databinding.DataBindingUtil
import androidx.navigation.Navigation
import com.example.twoscreens.databinding.FragmentOneBinding

/**
* A simple [Fragment] subclass.
*/
class fragmentOne : Fragment() {


   override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
       // Inflate the layout for this fragment

        val binding=DataBindingUtil.inflate<fragmentOneBinding>(layoutInflater,R.layout.fragment_one,container,false)
       binding.next_screen.setOnClickListener { view: View? ->
           if (view != null) {
               Navigation.findNavController(view).navigate(R.id.action_fragment_one2_to_fragment_two2)
           }
       }

       return binding.root

   }


}

我希望您可以在尖括号Bracket中看到FragmentOneBinding,现在它显示错误为unresolved referencence >>否,xml名称为fragment_one.xml

fragment_one.xml

<androidx.constraintlayout.widget.ConstraintLayout 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/fragment_one"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragmentOne">

    <!-- TODO: Update blank fragment layout -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/next_screen"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:gravity="bottom|center_horizontal|center_vertical|fill_vertical"
        android:text="Next Screen"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

请指导我并告知错误另外,如果您想查看其他文件,请在评论中说

fragmentOne.kt导入android.icu.lang.UCharacter.GraphemeClusterBreak.T导入android.os.Bundle导入androidx.fragment.app.Fragment导入android.view.LayoutInflater导入android.view.View ...

android android-fragments android-databinding
1个回答
0
投票

在xml中:

© www.soinside.com 2019 - 2024. All rights reserved.