Я пытаюсь добавить динамический c EditText в линейном макете по нажатию кнопки. Моя проблема заключается в том, что всякий раз, когда я нажимаю кнопку, успешно добавляется поле EditText, но под кнопкой «Я хочу показать EditText над кнопкой».
Мой root макет является линейным макетом
Ниже приведен мой код:
Файл макета
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/costLayout"
android:id="@+id/dynamicLayout">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rulingTypeWrapper"
android:layout_weight="1">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:hint="Add ruling type"
android:id="@+id/product_rule_type"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
</com.google.android.material.textfield.TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>>
<Button
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:id="@+id/addField"
android:text="ADD"
android:drawableTop="@android:drawable/ic_input_add"/>
</LinearLayout>
Java код
protected void createEditTextView() {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams (
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(16,10,16,10);
TextInputEditText edittTxt = new TextInputEditText(this);
int maxLength = 50;
hint++;
edittTxt.setHint("Ruling type");
edittTxt.setLayoutParams(params);
edittTxt.setInputType(InputType.TYPE_CLASS_TEXT);
edittTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
edittTxt.setId(hint);
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
edittTxt.setFilters(fArray);
parentLayout.addView(edittTxt);
}
Кто-то, пожалуйста, дайте мне знать, что я делаю не так. Любая помощь будет принята.
СПАСИБО