如何将我的应用程序的提取数据从firebase设置到我的bottomSheetView?(科特林)



这是我第一次在stackoverflow这里提问,我希望你能理解我是如何像新手一样构建这个问题的。所以,我在做一个顶点项目,特别是一个跟踪设备,我一直在取得进展,只是在这部分有点停滞不前。所以我想做的是,我希望从firebase数据库中提取的数据显示在我的底部视图中。此部分来自登录页面。

private lateinit var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login_page)
auth= FirebaseAuth.getInstance()
register.setOnClickListener {
var intent = Intent(this,Register_page::class.java)
startActivity(intent)
finish()
}
loginpage()
}
fun loginpage() {
val sharedPref = this.getSharedPreferences("logIn", Context.MODE_PRIVATE)?:return
val editor = sharedPref.edit()
editor.putBoolean("Finished", true)
editor.apply()

login.setOnClickListener {
if(checking()){
val email=email.text.toString()
val password= password.text.toString()
auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
var intent = Intent(this,MapsActivity::class.java)
intent.putExtra("email",email)
startActivity(intent)
Toast.makeText(this, "Welcome", Toast.LENGTH_LONG).show()
finish()
} else {
Toast.makeText(this, "Wrong Details", Toast.LENGTH_LONG).show()
}
}
}
else{
Toast.makeText(this,"Enter the Details", Toast.LENGTH_LONG).show()
}
}
}

private fun checking():Boolean
{
if(email.text.toString().trim{it<=' '}.isNotEmpty()
&& password.text.toString().trim{it<=' '}.isNotEmpty())
{
return true
}
return false
}

这部分来自我的登录页面,我希望在该页面中设置登录时获取的数据。

menu.setOnClickListener {

val sharedPref = this.getSharedPreferences("inMap", Context.MODE_PRIVATE)
val isLogin = sharedPref.getString("Email","1")
val editor = sharedPref.edit()
editor.putBoolean("Finished", true)
editor.apply()
var email = intent.getStringExtra("email")
Toast.makeText(this, "${email}", Toast.LENGTH_LONG).show()

if(isLogin=="1"){
var email = intent.getStringExtra("email")
if(email != null){
setText(email)
with(sharedPref.edit())
{
putString("email",email)
apply()
}
}else{
var intent = Intent(this,Login_page::class.java)
startActivity(intent)
finish()
}
}else{
db= FirebaseFirestore.getInstance()
var email=intent.getStringExtra("email")
if (email != null) {
Toast.makeText(this, "Woi, waya", Toast.LENGTH_LONG).show()
db.collection("USERS").document(email).get()
.addOnSuccessListener {
tasks->
name.text=tasks.get("Name").toString()
phone.text=tasks.get("Phone").toString()
emailLog.text=tasks.get("email").toString()
}
}
}
val bottomSheetDialog = BottomSheetDialog(
this, R.style.BottomSheetDialogTheme
)
val bottomSheetView = LayoutInflater.from(applicationContext).inflate(
R.layout.fragment_bottom_sheet,
findViewById<LinearLayout>(R.id.bottomSheet)
)

bottomSheetView.findViewById<View>(R.id.logout).setOnClickListener{
val sharedPref = this.getSharedPreferences("inMap", Context.MODE_PRIVATE)
sharedPref.edit().remove("Email").apply()
var intent = Intent(this,Login_page::class.java)
sharedPref.getBoolean("Finished", false)
startActivity(intent)
finish()
}
bottomSheetDialog.setContentView(bottomSheetView)
bottomSheetDialog.show()
}

这是xml文件,我试图在其中引用提取的数据

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/bottomSheet"
android:layout_width="match_parent"
android:background="@drawable/bottom_sheet_background"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIIT - SBMARS"
android:gravity="center"
android:padding="10dp"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="10dp"
android:background="@color/grey"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<com.makeramen.roundedimageview.RoundedImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:scaleType="centerCrop"
android:src="@drawable/siitlogo"
app:riv_corner_radius="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rodgin P. Misterio"
android:textColor="@color/black"
android:textSize="17dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="rodgin5@gmail.com"
android:textColor="@color/black"
android:textSize="15dp"/>
<TextView
android:id="@+id/emailLog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Digoy Residence"
android:textColor="@color/black"
android:textSize="17dp"
android:textStyle="bold"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@color/grey"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="12dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="10dp"
android:src="@drawable/logs"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:text="Sessions"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="12dp">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="10dp"
android:src="@drawable/logs"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:text="Logs"/>
</LinearLayout>
<Button
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Log-out"
android:background="@drawable/custom_button"
android:textColor="@color/white"
android:textSize="15sp"
android:textStyle="bold"/>
</LinearLayout>

请帮助胡湖

据我所知,这个问题的简单解决方案是创建一个打开底部表格的函数,并从.addOnSuccessListener内部传递3个所需值作为参数

功能声明-

fun openBottomsheet(name: String, email: String, phone: String) {
// open bottom sheet and pass these values to it
}

如果您可以使用数据绑定并创建一个视图模型来处理数据表示,那就太好了。您的数据将自动从数据库更新到您的底页上。

最新更新