0

I am making a Education Questionnaire App.

As far as layouts are concerned, there are 10 layouts:

1 Introduction Page

2 Main Selection

3 Chapter Selection

4 Completion page

5 Question Layout 1

6 Question Layout 2

7 Question Layout 3

8 Question Layout 4

9 Explanation Layout 1

10 Explanation Layout 2

I have already made these 10 XML layouts. (The whole layout changes, so fragment not possible)

Now comes the question of connecting them with Java.

Flowchart

After the Chapter Selection Page, the user answers 14 questions(Question Layout 1 to 4)with view data changed. Ideally, I want the back button to be used throughout the chapter so the stack will consist of 14 Activities per Chapter (1 question per screen/activity).

I need to confirm which is the best way to go about this.

Option 1

In total there are 120 chapters, so should I create 14 X 120 activities.(Sounds tiresome) Will it affect app usage speed?

Option 2

Restrict the back button to one per chapter (i.e. make one activity per chapter). Then I'll have to make 120 activities only.

In this case, in 1 activity, the 4 Question layouts will change view data 14 times (approx) with button clicks. How can I achieve this?

Search Results

I have found similar questions here but they talk about either using same layouts for each activity (Eg In Android, can I have different Activities use the same XML file?) or different view data per activity (Eg. Use single xml layout for multiple activities with different datas). A similar question (Using multiple layouts in single activity) was asked but the answers were not implementable.

Question

My question is : Which is the better option? In case Option 2, please give me a sample. I am using Android Studio 3.0

  • You need a ViewPager for sure! – Xenolion Nov 26 '17 at 23:00
  • @Xenolion Firstly, thanks for the suggestion. The thing is that the subsequent question is decided (if/else logic) based on the user selection in previous question. How can I do this with ViewPager? Please suggest if you know. – fightfought499 Nov 26 '17 at 23:06
  • Oooh okay if that is the case View pager is not the best alternative! – Xenolion Nov 26 '17 at 23:07
  • But I am expecting is that some layouts have same style way may be differing textView text only right – Xenolion Nov 26 '17 at 23:08
  • I'm sorry, @Xenolion but do you have any suggestions / know anyone who does? Please help me out. – fightfought499 Nov 26 '17 at 23:09
  • Surely I think I know, but I just do not have enough time and I have not got the whole idea or even where the questions are kept database or just string resources or static string? or got through http requests! – Xenolion Nov 26 '17 at 23:11
  • Yes, @Xenolion as I wrote in the question, the Views of the 4 Question Layouts get changed. So assuming you're suggesting Option 2, in each activity, both the layout and the view data is changing approx 14 times (in total). Please help me out. The string will be written in Java code, not Android resources. – fightfought499 Nov 26 '17 at 23:11
  • The string will be written in Java code, not Android resources. @Xenolion In case many layouts with different view text is implemented in 1 activity, how is it done? – fightfought499 Nov 26 '17 at 23:20
  • That makes the work even easier, You may have to find someone to do this project together is not easy for someone to solve that in stackoverflow. I believe with appropriate logic this can be a 4mb app. Having 120 activity will make your app too large. – Xenolion Nov 26 '17 at 23:24
  • @Xenolion Getting someone to do it for me would be ideal. But that will not be financially feasible right now. I would appreciate it if you could tell me the logic (no matter if its complex) Thanks so much. Do you know how that is done? – fightfought499 Nov 26 '17 at 23:28
  • Okay the issue/ logic is like prepare enough String arrays in code one for each category the start looping from one element to another one on button clicks while changing text. You can even animate so that will get a sensation that the views get to the next. Then all arrays must be connected in a logic to another array then the logic should be onClick of this fragment can opne another set of arrays! – Xenolion Nov 26 '17 at 23:33
  • @Xenolion Firstly, thanks for the answer. Are you suggesting one activity per Chapter(Option2)? By the way, do you know any such samples on GitHub, etc? Please suggest. That would be of immense help. Thanks. – fightfought499 Nov 26 '17 at 23:46
  • NO, I am sure there is a possiblity of having may 4 activities with few layout lets say 7 for your whole. But your options are not good! – Xenolion Nov 26 '17 at 23:48
  • Thanks a lot for your time. One more last request: How can multiple layouts AND different view text be implemented in a single activity? Do you have a random sample? – fightfought499 Nov 26 '17 at 23:51
  • In an activity the method `setContentView(id)` is what matters you can call it anywhere and still change the View of activity. If you still have no solution by next weekend check me on friday I will help you `johnnnoni@gmail.com`. You can count on me! – Xenolion Nov 26 '17 at 23:56
  • Thanks so much. That means alot to me. – fightfought499 Nov 27 '17 at 00:05
  • So did you finish the project successfully? – Xenolion Dec 02 '17 at 09:05
  • Thanks so much for remembering @Xenolion . About the "multiple layouts AND different view text in a single activity" -> I'll be using fragments in a frame layout.(Simple, huh?) But I'm still struggling with how to connect all the chapters with if/else. Thanks again. – fightfought499 Dec 03 '17 at 15:02
  • Oooh now you have updated your app logic, I haven't understood your new design although I guess its now good! If you stack somewhere my email is up there the third comment above this comment. – Xenolion Dec 03 '17 at 15:06
  • Hey @fightfought499 did you find a solution to this. I am in a similar situation and new to android. – edeesan Feb 16 '18 at 04:13

0 Answers0