I have a ScrollView which cointains a Linear Layout, When I create and add a EditText programatically to the layout my code is supposed to scroll to the bottom, but then the focus goes to the second from bottom field instead of what I want which is for it to focus the bottom field and I can't work out why.
Here is the code:
public void addPlayer(View view){
ScrollView scrollview = (ScrollView) findViewById(R.id.PlayerAddScroll);
EditText tv = new EditText(this);
tv.setHint("Player " + (playerCount + 1));
playerCount++;
tv.setSingleLine(true);
LinearLayout playerListView = (LinearLayout) findViewById(R.id.playerListView);
playerListView.addView(tv);
playerFields.add(tv);
scrollview.post(scrollBottom);
}
This is what scrollBottom does
Runnable scrollBottom=new Runnable() {
@Override
public void run() {
ScrollView scrollView = (ScrollView) findViewById(R.id.PlayerAddScroll);
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
};
My code causes this (Not focusing last field):