Android: Use component id as key in Array

0

I have an Android app that has 7 imageButtons , I need to store the captured images in a List Bitmap , I'm trying to set the array indexes as the id > imageButtons , however the application crashes when the procedure is performed.

public void tirarFoto(View view) {
  Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
  System.out.println(view.getId());
  idBotao = (ImageButton) findViewById(view.getId());
  startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
  if(data != null){
    Bundle bundle = data.getExtras();
    if(bundle != null){
      Bitmap img = (Bitmap) bundle.get("data");
      idBotao.setImageBitmap(img);

      //TENTA ADICIONAR A IMAGEM NO ARRAY USANDO O ID DO BOTÃO COMO CHAVE
      testeArray.add(idBotao.getId(),((BitmapDrawable) idBotao.getDrawable()).getBitmap());


      Log.e("ID Button",String.valueOf((int) idBotao.getId()));
    }
  }
}
    
asked by anonymous 10.10.2017 / 15:31

1 answer

2

Maybe it's some problem related to the index of the list, which in this case is the id of the ImageButton element. Try using a Map < int, Bitmap > to add its elements. For each Map you will add the element id and the Bitmap of the captured image.     

10.10.2017 / 16:10