I want to add buttons (based on the received info) in the main activity, so the number of buttons is not fixed.
I think the main code should be like:
for (int i=0; i<num; i++){
addButton(num); // The function for adding a button in layout and set all the parameters(id, text)
The parameters I want to change everytime and should be custom are:
- id name
- text
The following is the basic format I want to use for a single button (in activity_main.xml):
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="@drawable/bg"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="2dp"
android:layout_weight="3"/>
Does anyone know how to do it? Thanks.