Created
September 26, 2022 07:23
-
-
Save mikkipastel/46cda256101726bb2d346085e783c19f to your computer and use it in GitHub Desktop.
activity & fragment workshop : send EditText to show text of TextView at SecondActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ascedncorp.androidbasic | |
import android.content.Intent | |
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import com.ascedncorp.androidbasic.databinding.ActivityMainBinding | |
class MainActivity: AppCompatActivity() { | |
private val binding: ActivityMainBinding by lazy { | |
ActivityMainBinding.inflate(layoutInflater) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(binding.root) | |
binding.button.setOnClickListener { | |
val intent = Intent(this, SecondActivity::class.java) | |
intent.putExtra("text", binding.edittext.text.toString()) | |
startActivity(intent) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ascedncorp.androidbasic | |
import android.content.Context | |
import android.content.Intent | |
import android.os.Bundle | |
import androidx.appcompat.app.AppCompatActivity | |
import com.ascedncorp.androidbasic.databinding.ActivitySecondBinding | |
class SecondActivity: AppCompatActivity() { | |
private val text by lazy { | |
intent.getStringExtra("text") | |
} | |
private val binding: ActivitySecondBinding by lazy { | |
ActivitySecondBinding.inflate(layoutInflater) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(binding.root) | |
binding.textview.text = text | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment