我如何添加另一个String以及如何获取它。我尝试在同伴对象中添加另一个常量,但不起作用

问题描述 投票:0回答:1
class NewWordActivity : AppCompatActivity() {

    private lateinit var editWordView: EditText
    private lateinit var editTitleView: EditText


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_new_word)

        editWordView = findViewById(R.id.edit_word)
        editTitleView = findViewById(R.id.title_word)



        val button = findViewById<Button>(R.id.button_save)
        button.setOnClickListener {
            val replyIntent = Intent()
            if ((TextUtils.isEmpty(editWordView.text))) {
                setResult(Activity.RESULT_CANCELED, replyIntent)
                Toast.makeText(this, "Can not save empty fields", Toast.LENGTH_SHORT).show()
            } else {
                val word = editWordView.text.toString()
                val title = editWordView.text.toString()

                replyIntent.putExtra(EXTRA_REPLY, word)
               //How can I add title I have tried adding another constant but not working
                replyIntent.putExtra(EXTRA_SEND, title)
                setResult(Activity.RESULT_OK, replyIntent)

            }
            finish()
        }
    }

    companion object {
        const val EXTRA_REPLY = "com.example.android.wordlistsql.REPLY"
        //I addded this but still not working
        const val EXTRA_SEND = "com.example.android.wordlistsql.REPLY"
    }
}



I have tried passing data between the two actitvities but while doing that whenever I call the startActivity(intent) nothing is passed
android-room
1个回答
0
投票
收件人:-
© www.soinside.com 2019 - 2024. All rights reserved.