gpt4 book ai didi

java - add() 在android androidx.fragment.app.FragmentTransaction 中定义

转载 作者:行者123 更新时间:2023-12-05 00:18:19 26 4
gpt4 key购买 nike

无法调用某些 FragmentTransaction 方法。
例如,我想将 BlankFragment 添加到 FragmentContainerView 会导致以下错误。

  supportFragmentManager.commit {
setReorderingAllowed(true)
add<BlankFragment>(mainBinding.fragmentContainer)
}

None of the following functions can be called with the argumentssupplied.


enter image description here
这是我的 build.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'


implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'

// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

// Fragment
def fragment_version = "1.3.6"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
}
提前致谢。

最佳答案

reified add overload是 Kotlin 扩展方法(FragmentTransaction 本身是用 Java 编写的,因此它本身不支持该语法),这意味着您需要导入 Kotlin 扩展:

import androidx.fragment.app.add

关于java - add() 在android androidx.fragment.app.FragmentTransaction 中定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68568207/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com