安卓:根据选择的EditText显示ImageView的图像 [英] Android: Imageview showing an image according to edittext option

查看:100
本文介绍了安卓:根据选择的EditText显示ImageView的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的RES /文件夹绘制10动物形象,我想根据编辑文本选项逐一显示图像。我的意思是,当我们进入我们的体重编辑文本,按体重的范围内(如果体重是60-70图像视图之间显示老虎),每个重量图片视图显示不同的动物(根据范围)有不同的声音。由于我是新到Android我不能能解决这个问题,我们如何实现这一点?任何想法?

I have 10 animal images in my res/drawable folder and I want to show the images one by one according to the edit text options. I mean in the edit text when we enter our weight, according to the range of the weight (if weight is between 60-70 image view shows tiger) for each weight Image view shows different animal (according to range) with different sounds. As I am new to android I couldn't able to solve this, how can we Implement this? Any Idea?

帮助总是AP preciated ....!

Help is always appreciated....!

推荐答案

根据您的EDITTEXT值可以通过下面的函数值

As per your Edittext value you can pass that value in below function

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...
}

这篇关于安卓:根据选择的EditText显示ImageView的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆