0
I am creating a list of Edittexts programmatically. In all I give a margin of 20dp and place one below the other. The problem is that textbox2 is always on top of 1, the other textbox is in the perfect position. follow the code written to create the Edit Texts:
int numeroParcelas = 15;
for (int e = 0; e < numeroParcelas; e++){
final EditText myEditText = new EditText(mRlayout.getContext());
RelativeLayout.LayoutParams editParams = new RelativeLayout.LayoutParams(DrawerLayout.LayoutParams.MATCH_PARENT, DrawerLayout.LayoutParams.WRAP_CONTENT);
myEditText.setId(e);
myEditText.getLayoutParams();
myEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
myEditText.setHint("Parcela " + (e + 1) + ":");
myEditText.setHintTextColor(R.color.colorAccent);
myEditText.setTextSize(20);
if ( e > 0 ) {
editParams.addRule(RelativeLayout.BELOW, e -1 );
editParams.setMargins(0,20,0,0);
}else{
editParams.addRule(RelativeLayout.ALIGN_PARENT_START);
}
myEditText.setLayoutParams(editParams);
mRlayout.addView(myEditText);
}
If you take the line from the
editParams.setMargins(0,20,0,0);
, what happens?– Victor Stafusa
Will be all Edittexts on top of each other
– Matheus Suffi
What if instead of putting inside the
if
, you put right before themyEditText.setLayoutParams(editParams);
after the}
?– Victor Stafusa
Anyway. Actually that if was a test I just did
– Matheus Suffi