-3

I have four Images Google, Yahoo, GMail and I want if someone input in edit text Google then set imageview of Google.

For this I have made a raw folder inside res folder containing all the images and as someone input in edit text it is contained in String s (like s="Google") but I don't know how further set image

Shubham Sharma
  • 205
  • 2
  • 13

4 Answers4

-1

You can get Image as InputStream via this way

InputStream ins = getResources().openRawResource(
            getResources().getIdentifier("image name",
            "raw", getPackageName()));
Sabish.M
  • 2,022
  • 16
  • 34
  • Sir, How can I get multiple images by input stream like if user select both Yahoo and Google. Basically I am making a grid view of image and name so how can I get multiple images – Shubham Sharma Aug 23 '16 at 13:32
  • Add selected variable to arraylist and do what you need with forloop. – Sabish.M Aug 23 '16 at 14:04
-1
 int identifier = mContext.getResources().getIdentifier("file_name","raw", mContext.getPackageName());
    if(identifier>0){
        imageView.setImageResource(identifier);
    }
Ramesh R
  • 329
  • 1
  • 6
-2

Load you image from raw folder like this :

if(etText.equals("Google")    {
    InputStream imageIS = this.getResources().openRawResource(R.raw.google);
}
else if(etText.equals("Yahoo")    {
    InputStream imageIS = this.getResources().openRawResource(R.raw.yahoo);
}
else if(etText.equals("GMail")    {
    InputStream imageIS = this.getResources().openRawResource(R.raw.gmail);
}

Bitmap bitmap = BitmapFactory.decodeStream(imageIS);

and then load it in your imageview as :

 imageview.setImageBitmap(bitmap);
Pro Mode
  • 1,453
  • 17
  • 30
-2
int imageArray[] = {R.drawable.google, R.drawable.yahoo, R.drawable.gmail};

//onClick
String etStr = edittext.getText().toString();

if(etStr.equals("Google"){
     imageView.setImageResource(imageArray[0]);
}else if(etStr.equals("Yahoo"){
     imageView.setImageResource(imageArray[1]);
}else if(etStr.equals("GMail"){
     imageView.setImageResource(imageArray[2]);
}
Mohammad nabil
  • 1,010
  • 2
  • 12
  • 23