Search code examples
androidkotlintoastandroid-toast

toast message does not show up


when i run my app and click on button i need to see a message but Tost doesn't work.. what's the problem?

class MainActivity : AppCompatActivity() {
    lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.buttonSubmitUsername.setOnClickListener {
            if (binding.textInputUsername.text.toString().isEmpty()){
                Toast.makeText(this,"abc",Toast.LENGTH_SHORT).show()
            }else{
                val intent = Intent(this,QustionActivity::class.java)
                startActivity(intent)
            }
        }
    }
}

Solution

  • it was something wrong with my emulator... if you have the same problem you should try another device.