Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在片段';使用kotlin synthetic时创建的s OnViews不起作用_Android_Android Fragments_Kotlin_Synthetic - Fatal编程技术网

Android 在片段';使用kotlin synthetic时创建的s OnViews不起作用

Android 在片段';使用kotlin synthetic时创建的s OnViews不起作用,android,android-fragments,kotlin,synthetic,Android,Android Fragments,Kotlin,Synthetic,该值存在时,文本视图不会显示文本。此操作在onViewCreated inside fragment中调用。在相同的情况下,OnClickListener也不工作。 我搜索过类似的问题,但没有找到完全相同的案例。我错过什么了吗?谢谢你的帮助 import kotlinx.android.synthetic.main.fragment_login.* --- override fun onCreateView(inflater: LayoutInflater, container: ViewGr

该值存在时,文本视图不会显示文本。此操作在onViewCreated inside fragment中调用。在相同的情况下,OnClickListener也不工作。 我搜索过类似的问题,但没有找到完全相同的案例。我错过什么了吗?谢谢你的帮助

import kotlinx.android.synthetic.main.fragment_login.*
---

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                      savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_login, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    val isLogin = activity?.let { PrefHelper.getBoolean(it, PrefHelper.IS_LOGIN, false) }
    if (isLogin != null && isLogin) {
        onSignedIn()
    } else {
        onSignedOut()
    }
}

private fun onSignedIn() {
    form_login.visibility = View.GONE
    user_profile.visibility = View.VISIBLE

    var sEmail = ""
    var sFullName = ""
    var sPhone = ""
    if (activity != null) {
        PrefHelper.putBoolean(activity!!, PrefHelper.IS_LOGIN, true)
        sEmail = PrefHelper.getString(activity!!, PrefHelper.USER_EMAIL, "")
        sFullName = PrefHelper.getString(activity!!, PrefHelper.USER_FULL_NAME, "")
        val sPhonePrefix = PrefHelper.getString(activity!!, PrefHelper.USER_PHONE_PREFIX, "")
        val sPhoneSuffix = PrefHelper.getString(activity!!, PrefHelper.USER_PHONE_SUFFIX, "")
        sPhone = "$sPhonePrefix $sPhoneSuffix"
    }

    user_email.text = sEmail
    user_full_name.text = sFullName
    user_phone.text = sPhone

    logout.setOnClickListener { onSignedOut() }
}


为什么在你的Fragmneto中有两次
onCreateView(0
哦,很抱歉,这似乎是我在发送帖子时的错误。我将编辑帖子,感谢我在FragmentStatePagerAdapter中使用此片段。onSignedIn()方法在第一次调用时按预期工作。在移动到前3个片段后,它仍然会出现(viewpager)。但在“onDestroy活动”之后,出现了此问题。我在使用Java时从未发现此问题。这是Kotlin问题吗?