进度条没有出现- Kotlin



我一直在显示进度条时出现错误。下面是XML

的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress_bar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

然后在我的kotlin代码,我一直得到一个错误,显示我的进度条

OnCreate()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
init()
}

showRegisterLayout()-高亮部分是我的错误

private fun showRegisterLayout() {
val builder = AlertDialog.Builder(this,R.style.DialogTheme)
val itemView = LayoutInflater.from(this).inflate(R.layout.layout_register,null)
val edt_first_name = itemView.findViewById<View>(R.id.edt_first_name) as TextInputEditText
val edt_last_name = itemView.findViewById<View>(R.id.edt_last_name) as TextInputEditText
val edt_phone_number = itemView.findViewById<View>(R.id.edt_phone_number) as TextInputEditText
val btn_continue = itemView.findViewById<View>(R.id.btn_register) as Button
//set_data
if(FirebaseAuth.getInstance().currentUser!!.phoneNumber != null &&
!TextUtils.isDigitsOnly(FirebaseAuth.getInstance().currentUser!!.phoneNumber))
edt_phone_number.setText(FirebaseAuth.getInstance().currentUser!!.phoneNumber)
//view
builder.setView(itemView)
val dialog = builder.create()
dialog.show()
//Event
btn_continue.setOnClickListener {
if(TextUtils.isDigitsOnly(edt_first_name.text.toString())){
Toast.makeText(this@SplashScreenActivity,"Enter your First Name", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
else if(TextUtils.isDigitsOnly(edt_last_name.text.toString())){
Toast.makeText(this@SplashScreenActivity,"Enter your Last Name", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
else if(TextUtils.isDigitsOnly(edt_phone_number.text.toString())){
Toast.makeText(this@SplashScreenActivity,"Enter your Phone Number", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
else
{
val model = DriverInfoModel()
model.firstName = edt_first_name.text.toString()
model.lastName = edt_last_name.text.toString()
model.phoneNumber = edt_phone_number.text.toString()
model.rating = 0.0
driverInfoRef.child(FirebaseAuth.getInstance().currentUser!!.uid)
.setValue(model)
.addOnFailureListener{ e ->
Toast.makeText(this@SplashScreenActivity,""+e.message, Toast.LENGTH_SHORT).show()
dialog.dismiss()
progress_bar.visibility = View.GONE
}
.addOnSuccessListener {
Toast.makeText(this@SplashScreenActivity,"Registered Successfully", Toast.LENGTH_SHORT).show()
dialog.dismiss()
progress_bar.visibility = View.GONE
}
}
}
}

progress_bar.visibility = View.GONE是我的错误,progress_bar它一直显示红色。我试着修好它,但毫无进展。希望有人能帮助我:)

如果使用合成绑定,请确保从正确的xml布局文件中导入了progress_bar。

否则使用findViewById正确初始化progress_bar

我建议使用更安全的ViewBinding。

相关内容

  • 没有找到相关文章

最新更新