Skip to content
Advertisement

How to create dynamically class in Android

In my application, I should use Material Stepper and for this, I want to use this library : https://github.com/ernestoyaquello/VerticalStepperForm

But I want to add this dynamically from server.
For connecting with server I used Retrofit library and I should check the type of items from server.

when this type is “penny” show one of this steps and when the type is “best” show another step.

I create this steps from library tutorials, but i want when type is penny show me StepDynamicTxt and when the type is best show me StepDynamicEdt!

I write below codes but just add one of the items from each step!
But in API, I have 2 item of penny types and 3 items of best type!

Should show me 5 step, but show me 2 step!

My codes :

JavaScript

I think this problem for this line:}, stepDynamicEdt, stepDynamicTxt) because just add 2 step.

How can i add this step dynamically in Android?

Advertisement

Answer

In your code, you are making a very fundamental mistake. And that is, you are using the same variable each time in your loop to store dynamic edit type and dynamic text type, which will replace any previously created fields. And hence when you finally create them, you end up with single last values of each type.

What you can do is, create a List with type Step, add new type every time you get them, and finally pass that list to the builder.

The builder accepts a list too, you should check implementation when its open source.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement