Comments (15)
Hi @jagan999 , I cannot reproduce this. What I'm getting in the sample app is:
12-15 16:34:12.783 20403-20403/com.stepstone.stepper.sample I/System.out: position: 0
12-15 16:34:12.783 20403-20403/com.stepstone.stepper.sample I/System.out: position: 1
12-15 16:34:15.055 20403-20403/com.stepstone.stepper.sample I/System.out: position: 2
12-15 16:34:15.709 20403-20403/com.stepstone.stepper.sample I/System.out: position: 3
12-15 16:34:16.258 20403-20403/com.stepstone.stepper.sample I/System.out: position: 4
12-15 16:34:16.825 20403-20403/com.stepstone.stepper.sample I/System.out: position: 5
12-15 16:34:17.401 20403-20403/com.stepstone.stepper.sample I/System.out: position: 6
Could you provide more details?
from android-material-stepper.
Thanks for the reply. Here's my wizard activity complete with all steps. It may not work just like that since it has lot of links to my app code/logic. Can you tell me if there's an issue if the steps are static inner classes rather than separate fragment classes outside the wizard activity. I'm stuck on this, so any help will be great.
from android-material-stepper.
Hi, I cannot think why it would be an issue however I would strongly recommend extracting them to outer classes to improve readability. I cannot really tell much from this partial code, however the expected output in the console logs should be actually:
2016-12-14 19:29:48:position=0
2016-12-14 19:29:48:position=1
Since the next steps should be only created when they user actually reaches them. Are you sure you aren't using the adapter in any other ways?
from android-material-stepper.
Well, I'm truly stuck now. I copied your sample classes as attached, then invoked StyledTabsActivity from the same code that invoked my original wizard activity. It still prints out as follows when I expected it to only print position = 0, position = 1, position = 2 and then position = 0 since it goes to the first step in the StyledTabsActivity when launched. I'm really clueless as to why it behaves differently. Any hints? Here's what the AbstractStepperActivity printed out. I took your sample and added logging of position in createStep.
2016-12-18 12:14:34:position=0
2016-12-18 12:14:34:position=1
2016-12-18 12:14:34:position=2
2016-12-18 12:14:34:position=0
2016-12-18 12:14:34:position=1
from android-material-stepper.
Hi @jagan999,
I've discovered why we had a discrepancy. The behaviour you're describing is happening for the Material Stepper with tabs and I checked this this for the version with dots previously...
Anyway, the createStep method is used in TabsStepperType in onNewAdapter so that we can get the title of a tab.
When I think about it now this is something that might get actually moved to the adapter itself.
I am not sure though why this causing issues in your app. What exactly are you doing in createStep?
from android-material-stepper.
Yes, I observed this too when I tried playing with different stepper types. As indicated in the code I had attached previously, I'm only returning an instance of specific Step fragments in createStep. Nothing more than that.
from android-material-stepper.
Could you elaborate a bit more about:
"I am getting wrong behavior since the step positions are now already incremented by 1 because of the behavior above."
What do you mean by incrementing step positions? Where are you doing this?
from android-material-stepper.
I'm not incrementing anything myself. What I meant was that the position printed out has already moved to 1 when it should have been at 0 as previously indicated. So, when I now go to step 1, it gives position value as 2, when I go to step 6, it gives position value as 7 and so on and so forth...
from android-material-stepper.
OK, I think I get it now. The reason you're getting these logs in the console is because StepperLayout uses ViewPager internally. By default, ViewPager if you're on page N will create page N - 1 and N + 1. So if you're starting with the first page it will create the first and the second Fragment. If you go the second page it will also create the third Fragment and so on. The position you're getting in createStep is not the current step position.
from android-material-stepper.
Hi @jagan999, did that help solve your case?
from android-material-stepper.
I was on vacation and did not see your comment about ViewPager. While I understand the logic behind step position returned from ViewPager, can you pl suggest how I can correctly implement my logic when the stepper passes through the steps as shown in my sample code attached previously? I've for now worked around the issue by hardcoding the logic in onStepSelected for newStepPosition=6 but am not happy with this solution, even though it works.
from android-material-stepper.
Hi,
I'm not really sure what's the issue still... What are you trying to achieve? Would you like to show a message when the last step is shown?
from android-material-stepper.
Let me capture what I'm trying to do in my implementation of AbstractStepAdapter. Based on step position, sent by createStep(), I create instances of different StepperWizardStep fragments. In some of the fragments, I need to recalculate data if any of the other steps changed data. When the wizard is completed, I assemble all individual data elements from each step into a class and then create a JSON to store into the database. The issue here is that because of wrong step positions being returned by createStep() [as evidenced by the log statements in this issue thread], some of my step fragments don't get called and as a result, my recalculation fails. Hope this clarifies. And BTW, on the last step fragment, I indeed show a summary of all data that was input in the wizard for reconfirmation before issuing the database insert/update.
from android-material-stepper.
Ok, I get it now. In this case you might consider keeping that data in a common place to be used by all the fragments, e.g. in the parent Activity or a shared component (one you could e.g. inject with Toothpick). You could use Step#onSelected() to update the fragment then. As mentioned earlier, createStep() is not said to be triggered once you actually see the fragment.
Having said that, I plan to change the logic so that createStep() would not need to get called just to get the title for the tab in the future release. However, even with that done createStep() would get called for the first two fragments.
from android-material-stepper.
I do actually have my class shared at the activity level and incrementally populate it in every step of the wizard. As stated, I'm already implementing my logic in onStepSelected but perhaps I'll move that logic to Step#onSelected like you suggest. So, you can close this issue for now since my workaround works.
from android-material-stepper.
Related Issues (20)
- new AndroidX library migration. HOT 1
- Skip step 2 verification and go to step 3 from step 1
- How to remove numbers from tabs? HOT 1
- Using a Singleton to keep data HOT 6
- Remove or Add Steps Conditionally HOT 1
- how to change icons and text in stepperLayout?
- How can i change the back button background with androidx HOT 1
- java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[])' on a null object reference HOT 6
- Is there any well-supported fork out there? HOT 6
- it takes much time to create the activity hosting stepper fragments (about secs which is very long for the UI Thread)
- Having Issue applying style on StepperLayout HOT 1
- Please find a solution to this problem
- verify
- Error
- Can't change back and next button text programmatically HOT 1
- Padding next button and final button HOT 1
- move library to mavenCentral or other repo, Jcenter() is Deprecated HOT 3
- The fragments inside stepper shrink completely when keyboard is opened
- Step fragment is not working properly after recalling HOT 1
- Adapter Position issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-material-stepper.