1

I am overlapping couple of view's dynamically in my app over a bitmap. I would like to delete those view's before saving the bitmap to gallery. Below in the function which adds view's on my bitmap

public void add()
{
    relLayout.addView(newRect);
    relLayout.addView(newSpeech);
    relLayout.addView(editImgv);
    relLayout.addView(resizeImgv);
}

There is a button on pressing it the above add() function gets called and all those views get added over my bitmap again.

Before saving the bitmap I would like to delete all editImgv and resizeImgv which were added over my bitmap.

Any ideas on how to do it? Thanks in advance :)

ik024
  • 3,566
  • 7
  • 38
  • 61
  • Similar to http://stackoverflow.com/questions/3805599/add-delete-view-from-layout ? –  Jan 13 '14 at 10:21
  • if i use ((ViewManager)resizeImgv.getParent()).removeView(resizeImgv); inside the touchListener of that view it works but if i use it in a function it gives null pionter error – ik024 Jan 13 '14 at 10:51
  • Then you have a scope issue -- that view may not be available b/c you're on a different thread or such. –  Jan 13 '14 at 10:54
  • since i am creating multiple instance of each view i am not able to get the scope of those views. do u have any idea how to tackle this? – ik024 Jan 13 '14 at 11:37
  • i tried using View v = relLayout.getChildAt(6); ((ViewGroup)v.getParent()).removeView(v); but i want to make it dynamic – ik024 Jan 13 '14 at 11:38
  • There's not enough code or description for me to know what I'd need to help. –  Jan 13 '14 at 11:46

1 Answers1

3

I have resolved it by using Vector arrays - I placed all the 'resizeImgv' and 'editImgv' image views which I am adding dynamically in a vector array of type 'ImageView' and when I am about to save I am just setting their visibility to 'GONE' one by one. It was a simple solution in the end :)

//Global  
Vector<ImageView> imgv = new Vector<ImageView>();

....    

//Adding views to my vector array
public void setImageViewArray(ImageView imgview){
    imgv.add(imgview);
}

.....

//when I am about to save
for(int i = 0; i < imgv.size(); i++ ){
    if(imgv.get(i).getVisibility() == View.VISIBLE){
        imgv.get(i).setVisibility(View.GONE);
    }
}
ik024
  • 3,566
  • 7
  • 38
  • 61