We are developing a communication board for people with a certain degree of difficulty, being able to communicate through a communication board. In case you might inadvertently add more than one image (get duplicate), then I would need to delete this last button.
As the use is for those who have a certain degree of difficulty, we think of leaving the delete function on a button (as indicated in the image circled in red), when pressed, delete the last ImageButton added.
Any ideas how to do this? It is added to a LinearLayout in a ScroolView.
Below is the code to add the
//Função para Criar Botões
protected void criaBotoes(final int idBotao, final int posicaoX, final int posicaoY, final int altura, final int largura, int tipoLayout, int tipoBotao, String pathArquivo, final int tagBotao) {
AssetManager manager = getAssets(); //Pasta onde ficam os arquivos a serem carregados ( Imagens )
//Carrega Imagens dinamicamente
InputStream open = null;
try {
open = manager.open(pathArquivo); //Seta nome para carregar o arquivo
Bitmap bitmap = BitmapFactory.decodeStream(open); //Seta objeto para controle de imagem
//Cria Layout Params ( "Fatias no layout para adiocionar cada botão )
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//Seta posições e tamanho do Botão
params.leftMargin = posicaoX;
params.topMargin = posicaoY;
params.width = altura;
params.height = largura;
ImageButton botaoImg = new ImageButton(this); //Cria Botão Dinamicamente
botaoImg.setId(idBotao); //Seta propriedade ID para cada usuário, para ser usado no "Click"
botaoImg.setTag(tagBotao); //**
botaoImg.setBackgroundResource(0); //Deixa botão sem bordas
botaoImg.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int id = v.getId();
int tag = (int) v.getTag();
//...
}
});
botaoImg.setImageBitmap(bitmap); //Seta objeto de imagem para o Botão
botaoImg.setLayoutParams(params); //Seta layout para o botão ( "Fatias" para cada botão )
ll.addView(botaoImg); //Adiciona Botão no Layout (Linear)
} catch (IOException e) {
e.printStackTrace();
}
}
criaBotoes(seqBotoesSel, posX, posY, altura, largura, 1, 1, pathAquivo, 0);
sv.addView(ll); //adiciona botão na ScrollView