Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication
- import android.R.attr
- import android.media.MediaPlayer
- import androidx.appcompat.app.AppCompatActivity
- import android.os.Bundle
- import android.widget.ImageView
- import android.widget.TextView
- import android.R.attr.delay
- import android.os.Handler
- ㄒㄩ˙ㄉ
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val apple = findViewById<ImageView>(R.id.apple)
- val banana = findViewById<ImageView>(R.id.banana)
- val lemon = findViewById<ImageView>(R.id.lemon)
- val orange = findViewById<ImageView>(R.id.orange)
- val pumpkin = findViewById<ImageView>(R.id.pumpkin)ㄋ
- val tomato = findViewById<ImageView>(R.id.tomato)
- apple.setOnClickListener{
- pSoundnCText("apple")
- pressEvent(apple)
- }
- banana.setOnClickListener{
- pSoundnCText("banana")
- pressEvent(banana)
- }
- lemon.setOnClickListener{
- pSoundnCText("lemon")
- pressEvent(lemon)
- }
- orange.setOnClickListener{
- pSoundnCText("orange")
- pressEvent(orange)
- }
- pumpkin.setOnClickListener{
- pSoundnCText("pumpkin")
- pressEvent(pumpkin)
- }
- tomato.setOnClickListener{
- pSoundnCText("tomato")
- pressEvent(tomato)
- }
- }
- fun pressEvent(image :ImageView){
- image.alpha = 0.4f
- Handler().postDelayed(Runnable {
- //execute the task
- image.alpha = 1f
- }, 50)
- }
- fun pSoundnCText(id :String) {
- val mp: MediaPlayer = MediaPlayer.create(this, resources.getIdentifier(id, "raw", packageName))
- val show = findViewById<TextView>(R.id.Show)
- mp.start()
- show.text = id.get(0).uppercase() + id.substring(1).lowercase()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement