EDAS19
EDAS19

Reputation: 3

How can i check if TextView is not empty in Kotlin?

I am building my first App. My question is:

How can i put the Intent into "liste2" when "liste1" is not empty?

My Code:

 private fun insertTextToTv() {
        val liste = findViewById<TextView>(R.id.liste)
        val liste2 = findViewById<TextView>(R.id.liste2)
        val liste3 = findViewById<TextView>(R.id.liste3)

        if (liste.text.toString() == "") {
            liste.text = intent.getStringExtra("key")
        } else {
            liste2.text = intent.getStringExtra("key")
        }

    }
}

The Intent of the other Activity:

 private fun favoritesButtonSaveText(){
        favorisieren.setOnClickListener{
            val save = Intent(this, favorites::class.java)
            save.putExtra("key", sourceTextField.text.toString())
            startActivity(save)
        }


    }

Thank you for your help and time!

Upvotes: 0

Views: 397

Answers (1)

Muhammad Ahmed
Muhammad Ahmed

Reputation: 1048

private fun insertTextToTv() {
        val liste = findViewById<TextView>(R.id.liste)
        val liste2 = findViewById<TextView>(R.id.liste2)
        val liste3 = findViewById<TextView>(R.id.liste3)

        if (liste.text.isNotEmpty()) {
            liste2.text = intent.getStringExtra("key")
        } 

    }

}

Upvotes: 1

Related Questions