Android: Use component id as key in Array

Asked

Viewed 37 times

0

I have an Android app that has 7 imageButtons, need to store the captured images in a List Bitmap, I am trying to define the indices of the array list as the id of the imageButtons, however the crash application 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()));
    }
  }
}

1 answer

3


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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.