Skip to content Skip to sidebar Skip to footer

Dynamically Add Edittext To A Relative Layout Under An Existing Edittext

I am trying to add an editText dynamically to a relative layout. the layout contains an editText already. I need to add the new editText below the existing one. EditText designatio

Solution 1:

You need to use RelativeLayout.LayoutParams and specifiy the relative position with the addRule(RelativeLayout.BELOW, ...) (this is the programmatic equivalent for android:below XML attribute):

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, R.id.editTextDesignatn);
layoutExp.addView(designation1, params);

Solution 2:

It will be possible if You set for example a LinearLayout under Your existing EditText. Give an ID to this LinearLayout and then You could put Your dynamic EditText to this LinearLayout like

    YourLinearLayout.addView(YourDynamicEditText);

Post a Comment for "Dynamically Add Edittext To A Relative Layout Under An Existing Edittext"