String in findViewById

0

Hello, I was wondering if you can use a string in findViewById. I have an app with several imageview that when calling a call to the camera's camera. So that I do not need to put this intent and its startActivityforResult for each imageview, I thought about creating a string to change the id of each imageview according to the selected imageview. Ex:

 image=(ImageView)findViewById(R.id(aqui colocar o código de uma string);
 image.setImageBitmap(imageCamera);

Is it possible? Thanks

    
asked by anonymous 04.07.2018 / 21:16

1 answer

1

I suggest you do this using HashMap , since you want to have control via String .

It would look something like this:

  Map<String, Integer> map = new HashMap<String, Integer>();

    map.put("Image1",R.id.imageView1);
    map.put("Image2",R.id.imageView2);
    map.put("Image3",R.id.imageView3);

To retrieve the id, for your findView , you would do something like this:

 image=(ImageView)findViewById(map.get("Image1"));
    
05.07.2018 / 21:14