This is what i am doing in coding i want to create controls on button click. The number of times the user will click i want to add controls for the same number of time..
I have to add these controls in relative layout. which i had already created in xml layout with one set of controls already in it.. and want to make it working for more controls if user want to edit.
View DynamicView= new View(this);
DynamicView.setId(123);
DynamicView.setLayoutParams(new LayoutParams(1, LayoutParams.MATCH_PARENT))
The following is XML layout code.
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
problems:-
1) dont want to give ids this way 🙁
DynamicView.setId(123);
want to assign such ids as we can assign in xml layout
android:id="@+id/spnrIngredients1"
2) how to give values for relative layouts in coding such as
android:layout_toRightOf="@id/tvIngredientsName"
android:layout_toLeftOf="@id/tvIngredientsName"
android:layout_below="@id/tvIngredientsName"
android:layout_above="@id/tvIngredientsName"
3) how to give values for background colors.
it is not accepting hexadecimal codes or something else.. what type of int values it is asking for..?
2) Use the
LayoutParamsto set the rules for placing the views in theRelativeLayout:The above code will place the
Buttonbellow the view with the idviewID.3)
setBackgroundColor()(I think this is the method you are using) requires an int representing theColor, you can set it in that method this ways:1) You could set your ids in a
values/ids.xmlfile and later set them to your views and then refer the views by those ids:Now you can use the id
R.id.myfirstidin your code(I don’t know if this is what you want).NOTE:
I don’t know if this is recommended.