Solution 1 :
An optional route out is have a recyclerview with an edittext and an initial item size of 3 and then you can add more edittexts once the last item on the recyclerview is clicked or active.
Problem :
I have a fragment with a scrollview. Initially there are 3 edit texts which I add programatically not through the xml. The desired functionlty is when the user clicks the last edit text i.e number 3 it will automatically add a 4th edit text directly below it. When the user clicks on the 4th edit text it will add a 5th and so on. My code which is shown below is almost working. When the user clicks on edit text 3 it will add a 4th and when they click on the 4th it will add a 5th, however after that it will not add anynore edit texts.
I have an onFocusChange listener and I also notice this listener only activates on the 3rd and 4th edittexts. For some odd reason the listener doesnt activate when clicking on any other edit texts.
// Adds 3 edit texts to the view which are stored in an array list.
for (int etId = 0; etId <= 3; etId++) {
etChallenges = new EditText(getContext());
editTextList.add(etChallenges);
mLinearLayout.addView(etChallenges);
}
etChallenges.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
int last = 0;
for(last =0; last <= editTextList.size()-1; last++){
if(last == editTextList.size()-1){
etChallenges = new EditText(getContext());
editTextList.add(etChallenges);
mLinearLayout.addView(etChallenges);
break;
}
}
Comments
Comment posted by AndroidDev123
That is a nightmare dealing with the recyclerview or list view, been there tried that.