내 대화 상자 조각을 로그인 조각으로 호출하려고하고 경고 대화 상자를 표시하려고하면 show 메소드에 다음과 같이 표시됩니다.
와이즈 비즈None of the following functions can be called with the arguments supplied. show(FragmentManager!, String!) defined in org.greenstand.android.TreeTracker.fragments.CustomDialogFragment show(FragmentTransaction!, String!) defined in org.greenstand.android.TreeTracker.fragments.CustomDialogFragment
내 CustomDialogFragment 코드는 다음과 같습니다.
val newFragment = CustomDialogFragment.newInstance("pass content here")
val fm = fragmentManager
newFragment.show(fm, "look")
누군가가 show 메소드에 정확히 전달해야하는 것을 나타낼 수 있습니까? 어떤 도움이라도 감사합니다 :)
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_login.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.greenstand.android.TreeTracker.R
import org.greenstand.android.TreeTracker.application.Permissions
import org.greenstand.android.TreeTracker.utilities.*
import org.greenstand.android.TreeTracker.viewmodels.LoginViewModel
import org.koin.android.viewmodel.ext.android.viewModel
import timber.log.Timber
class CustomDialogFragment : DialogFragment()
{
private var content: String? = null
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
content = arguments!!.getString("content")
val style = DialogFragment.STYLE_NO_FRAME
val theme = R.style.DialogTheme
setStyle(style, theme)
}
override fun onAttach(context: Context) {
super.onAttach(context)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle): View
{
val view = inflater!!.inflate(R.layout.layout_dialog, container, false)
val btnAccept = view.findViewById<View>(R.id.buttonAccept) as Button
val textViewContent = view.findViewById<View>(R.id.textViewContent) as TextView
textViewContent.text = content;
btnAccept.setOnClickListener{
dismiss();
}
return view;
}
companion object
{
fun newInstance(content: String) : CustomDialogFragment
{
val f = CustomDialogFragment()
val args = Bundle()
args.putString("content", content)
f.arguments = args
return f
}
}
}
- 답변 # 1
- 답변 # 2
활동이 https://developer.android.com/reference/androidx/fragment/app/FragmentActivity.html의 하위 항목인지 확인하십시오. 예를 들어 https : // developer를 사용할 수 있습니다. 부모 활동으로서 android.com/reference/androidx/appcompat/app/AppCompatActivity.
그런 다음 fragmentManager를 얻으려면getSupportFragment()
를 사용하십시오. 방법 또는 그냥val fm = supportFragmentManager
- 답변 # 3
DialogFragment
가 보이지 않습니다 당신의customDialog()
에 수입 수업. 실제로line no: 9
에 Fragment import가 있습니다. . 올바른DialogFragment
에서 확장하고 있습니까? ?
관련 자료
- android - 호출 사이트에서 nullable 인수를 확인해야하는 경우 Kotlin에서 Java 메서드를 호출 할 때 어떻게 알 수 있나요?
- android - Kotlin이 조각에서 버튼 ID를 찾을 수 없습니다 이유가 무엇입니까?
- Kotlin - 코 틀린 - 코 루틴 채널 :그들은 호출 스레드를 차단합니까?
- 안드로이드 kotlin에서 조각으로 컨텍스트를 초기화하는 방법
- android - Fragment에서 FragmentManager를 어떻게 호출합니까? 코 틀린
- android - DialogFragment가 표시되면 조각 뒤를 클릭하십시오
- android - 다른 조각을 호출하는 recyclerview 조각이있는 탐색 창
- android - 대화 상자에서 조각 메서드 호출
- java - 다른 프래그먼트에서 메소드 호출
- java - 안드로이드에서 조각을 호출하지 않고 조각에 대한 리스너
- android - 코 틀린 조각에서 스피너가 작동하지 않습니다
- android - dialogfragment - 조각이 생성 될 때 애니메이션을 한 번만 표시
- android - Kotlin에서 활동에서 조각의 메소드를 호출하고 동시에 조각으로 데이터를 보내는 방법
- android - kotlin - 프래그먼트 내부의 fragmentmanager가 null이 됨
- Kotlin Android "onbackpressed"는 아무것도 겹쳐 씁니다
- android : 조각 사이를 탐색하는 두 가지 방법이있는 이유는 무엇입니까?
- Kotlin Android Studio Fragment의 해결되지 않은 참조
- android : 맨 아래 Navmenu 버튼을 사용하여 조각을 열면 Jetpack DataStore에서 인수 (탐색 구성 요소)로 조각으로 int를 전달하는 방법은 무엇입니까?
- android : FragmentContainerView의 이름 속성에 NavHostFragment를 사용하는 이유
- android : Kotlin을 사용하여 조각을 완성하는 방법
- android : 관찰 방법이 조각에서 올바르게 작동하지 않습니다
- android : 조각간에 값을 전달합니다
- java : 두 번째 조각 내용은 오류 android kotlin을 탐색 한 후 변경되지 않습니다.
- 스플래시 프래그먼트로 Android Jetpack 탐색 구성 요소 문제 루트 대상
[업데이트] 문제는 방법이
FragmentManager
를받을 수 있다는 것입니다 하지만 감사 할 필요는 없습니다. 오류와 감사하지 않는 Kotlin 기호를 살펴보세요FragmentManager!
그래서 할 수있어
Noushad Hasan 답변의 의견을 참조하십시오
당신은
FragmentManager
를 통과하고 있습니다 이 방법에는FragmentTransaction
가 필요합니다. 그리고String
태그로 :몇 가지 제안 :
당신은 당신을
DialogFragment
만들 수 있습니다 Kotlin 표준 기능을 사용하여 더 많은kotlinyFragment
를 만들어 좋은 예를 얻을 수 있습니다 Android Studio 마법사를 사용하고 공장 방법 옵션 확인또한 태그가 당신의
DialogFragment
를위한 것이기 때문에 공개 상수로 만들 수 있습니다 :대화 상자 조각이 이미 있는지 다시 확인하고 제거하여 실제로 새 대화 상자로 작동하고 싶을 수도 있습니다