Issue
does anyone know how to pass values editText from activity 1 to editText activity 2 using intent or bundle?
this is the first activity this is the second activity
this is the code, the EditText values from activity 1 still not showing in EditText activity 2
this is mainActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val emailEt = findViewById<EditText>(R.id.et_email)
val passEt = findViewById<EditText>(R.id.et_password)
val nextBtn = findViewById<Button>(R.id.next)
nextBtn.setOnClickListener{
val intent = Intent(this, SecondActivity::class.java)
val email = emailEt.text.toString()
val pass = passEt.text.toString()
intent.putExtra("email", email)
intent.putExtra("pass", pass)
startActivity(intent)
}
}
}
this is SecondActivity
class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
val email = intent.getStringExtra("email")
val pass = intent.getStringExtra("pass")
}
}
Solution
Use Intent.putExtra()
in first activity and getIntent().getStringExtra()
in second activity by modifying your second activity as
class SecondActivity : AppCompatActivity() {
val emailEt = findViewById<EditText>(R.id.et_email)
val passEt = findViewById<EditText>(R.id.et_password)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
val email = intent.getStringExtra("email")
val pass = intent.getStringExtra("pass")
emailEt.setText(email)
passEt.setText(pass)
}
}
Answered By - Junaid Khalid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.