I have a button that when a user clicks, it dynamically adds editTexts' and a clickable TextView ("X") which should delete its corresponding editText, to its layout. The number of editTexts' and TextView created are based on the number of times the button is clicked. But I now want to remove the editText when I click on the clickable TextView ("X")
View.OnClickListener generate = new View.OnClickListener() {
@Override
public void onClick(View view) {
for (int i = 0; i < count; i++) {
addEdits = new EditText(getSymptomsActivity.this);
cancel=new TextView(getSymptomsActivity.this);
addEdits.setLayoutParams(new ActionBar.LayoutParams(400, 79));
addEdits.setText("");
cancel.setText("X");
platform.addView(addEdits);
platform.addView(cancel);
values.add(addEdits);
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for(int j = count; j>0 ; j--){
platform.removeView(addEdits);
//values.remove(addEdits);
cancel.setVisibility(TextView.GONE);
}
}
});
The issue at the moment is that, when the clickable TextView("X") is clicked it only deletes the last created editText and only that.