Android:Imageview 根据 edittext 选项显示图像

标签 android imageview android-edittext

我的 res/drawable 文件夹中有 10 张动物图像,我想根据编辑文本选项一张一张地显示这些图像。我的意思是在编辑文本中,当我们输入体重时,根据体重的范围(如果体重在 60-70 之间, ImageView 显示老虎),每个体重 ImageView 显示不同的动物(根据范围)和不同的声音。由于我是 android 的新手,我无法解决这个问题,我们该如何实现呢?有什么想法吗?

帮助总是感激......!

最佳答案

根据您的 Edittext 值,您可以在下面的函数中传递该值

private void displayImg(int value){
    ImageView im = (ImageView)findViewById(R.id.img1);
    if (value >= 0 && value < 10){
        im.setBackgroundResource(R.drawable.animal1);
    }else if (value >=10 && value <20){
        im.setBackgroundResource(R.drawable.animal2);
    }
            ..... so on...
}

关于Android:Imageview 根据 edittext 选项显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6223232/

相关文章:

Android:恢复带有动画 View 的 Activity 后,如何启动应用于 ImageView 的无限动画?

android - 使用可编辑和不可编辑的提示/文本编辑文本 - Android

Android XML - 没有换行符的 EditText 自动换行

java - BitmapFactory.decodeByteArray 运行时异常

android - Linux支持splice()和sendfile(),Android呢?

android - 按文件名显示图像

android - EditText 在动画后卡住并在滚动时恢复正常......?

android - 刀柄 (Android) : cannot find symbol return DaggerApp_HiltComponents_ApplicationC. builder()

android - 错误的IDE Android Studio

android - 空 ImageView 引用