• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ViewPager questions

RhinoCan

Well-Known Member
Jul 5, 2015
184
64
I'm starting to design my next app. It is basically an app to model a 50/50 draw. A 50/50 draw works by selling tickets to people that belong to an organization; they buy as many tickets as they want at a fixed rate, then one of the tickets is drawn at random and the winner gets half of the money collected (and possibly additional prizes). The organization running the draw keeps the rest of the money.

Things have to be done in a specific sequence, although some of the steps may be repeated. Right now, I'm envisioning 4 steps:
  1. Selling chances - each ticket buyer specifies the number of tickets they want; the app calculates the total owed for the tickets and assigns that number of tickets to the buyer; the person executing the app collects the amount owed for the tickets (cash only) and puts it aside. This process repeats until everyone who wants a ticket, has one.
  2. Generating tickets - the app generates virtual tickets for each buyer and displays them on the screen (which will be connected to a projector that makes it visible throughout the room).
  3. Draw winner - choose one of the virtual tickets at random and display that ticket number for the room to see (plus "special effects": a drum roll as the winning ticket is being chosen and canned applause as the winner is named).
  4. Draw additional tickets - sometimes, additional prizes are available and the second ticket drawn gets first chance to choose from those prizes; third ticket drawn gets what's left after second ticket owner claims his/her prizes, etc.
While doing Step 1, the user cannot jump ahead to any later step; when *finished* Step 1, the user clicks a button to go to Step 2. While doing Step 2, the user can go back to Step 1 if a late arrival wants a ticket (or, conceivably, if someone who bought a ticket changes their mind about wanting it) but they can't move on to Step 3 until everyone is satisfied that they know what their tickets are and they got the quantity of tickets they wanted. When *finished* Step 2, the user clicks a button to go to Step 3. When the winning ticket has been drawn, the user can go back to Step 2 to review who bought what tickets in case there's any doubt about who the winner was but the user cannot go back to Step 1 and can NOT click the Draw button to force choosing a new ticket but they can return to the result of Step 3 to see who the winner was. When completed Step 3, the user can click on a button to do Step 4 if there are additional prizes in this case; otherwise, there's no point in executing Step 4.

Now, finally my questions. I *think* this app is best based on a TabLayout with one tab for each of the 4 steps listed above. I think ViewPager is going to be pivotal here to control going from one page to the next. Before I go too far down the wrong path here, I want to be sure that I can prevent the user from tabbing or swiping forward or back when they haven't finished a given step.

Is that possible? Or do I need to go about this in a whole different way? If I need a different approach, what would you suggest?

If this *is* the right way to proceed, which methods do I use to control paging and prevent it or allow it depending on what has happened in the app?

This has to be a fairly standard model for an app given that there are lots of situations where things have to be done in a given order. For instance, a recipe won't turn out well if a critical ingredient is added after the cooking is done. I'm looking for the best way to get things done in a certain order but that still allows some flexibility for parts of the task where sequence isn't critical.

I'd appreciate any advice anyone can offer.
 
That sounds a bit like Gambling or some type of raffling system if it's not a legitimate event taking place for the said tickets to be sold. You may want to speak with your local gambling Commission before taking any more steps in constructing that app to see if it infringes on any gambling laws.

Thanks for your concern but I'm really not worried about the legalities. It's an organization that has been in existence for almost 40 years and it's essentially a fund-raising activity for the organization which is a non-profit. The volume of money raised is VERY small, under $10 most times we have this draw.I'm just trying to do the draw via an app rather than with paper tickets.
 
  • Like
Reactions: KBU2
Upvote 0
I wouldn't do this with a tab layout. Your application follows a 'wizard' type approach, where the user does things in a sequential order. That doesn't really suit a tabbed layout, which allows the user to swipe arbitrarily between tabs.
I'd probably use Fragments for this. These are ideal for when you want to dynamically change Views on a screen. So each Fragment would display the functions of that particular step, and include forward/back buttons as required.
 
Upvote 0
I wouldn't do this with a tab layout. Your application follows a 'wizard' type approach, where the user does things in a sequential order. That doesn't really suit a tabbed layout, which allows the user to swipe arbitrarily between tabs.
I'd probably use Fragments for this. These are ideal for when you want to dynamically change Views on a screen. So each Fragment would display the functions of that particular step, and include forward/back buttons as required.

Thank you. I was beginning to suspect I was doing things that were beyond the design intentions of a TabLayout. So, simply using fragments (or activities) with buttons of my own creation would be better and the tabs are not especially useful in this case. That's good to know.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones