I have an arraylist:
List<EditText> controlsOptionsET = new ArrayList<EditText>();
And what I’m doing is that I’m dynamically adding a textbox and a button at the side of the textbox which is a delete button to delete the textbox. Every time I add the textbox the textbox should have a hint of option 1, next textbox option 2, option 3, and so on. But when I delete option 2 textbox the textbox hints should revaluate so now textbox 1 should be option 1 and textbox 3 should now have option 2 instead of option 3 because that textbox at option 2 got deleted.
This is my loop code as I’m reiterating through the controls list;
btnDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup) lin2).removeAllViews();
((ViewGroup) lin).removeAllViews();
lin.removeView(v);
lin2.removeView(v);
p.setMargins(0,0,0,0);
ll.setMargins(0,0,0,0);
int index = 0;
int cntEt = 3;
for(int i = 0; i < controlsOptionsET.size(); i++){
EditText editText = controlsOptionsET.get(i);
if(controlsOptionsButton.get(i) == btnDel){
controlsOptionsButton.remove(i);
controlsOptionsString.remove(i);
controlsOptionsImg.remove(i);
controlsOptionsTV.remove(i);
controlsOptionsET.remove(i);
}else{
editText.setHint("Option " + cntEt);
cntEt++;
}
}
//lin2.removeAllViews();
}
});
I’m starting at cntET at 3 because the first two textboxes are fixed and must be filled in.