L开发者_Go百科ets say, I want to make a quiz application. And I have 90 question - 3 question on each activity which is 30 activity. The way I know how to make all those Activities is to make a class for each of them. 30 class is a lot.
I'm using this method:
startActivity(new Intent(this, Myclass.class));
What is the best way to make all those activities? Or can it all happen in one?
Thanks, comment if something is not explained clearly.
I would try to separate the data (the questions/answers) from the view (the activities) and use some Intent.putExtra()
to open one quiz activity with a parameter to let it know which questions to load/show.
I am not sure, but I think that to share the questions data between the activity instances you could put them in a static variable in that activity.
If the plan is to go like start quiz -> good answer -> start another quiz -> ...
then you might want to use android:noHistory
to avoid leaving all old question activities in memory.
One thing that you could do is use a viewflipper within a single activity, to show a few different views there. Perhaps you could group your questions and use a single activity for each group, using the viewflipper for each group...
bigstones is correct. You need to separate the data from the Activity, and only create a single Activity. Then, you could have a button that they click when they've answered the set of questions they're currently viewing. Clicking that button would show a progress spinner, and then load the next 3 questions in the background. This should all be done with a single Activity.
Mauzam. I have a better solution . You could also use one activity ,and use an Expandable List view instead. this activity will have all the question in it and when someone clicks on a particular question, this list view would expand to show the options and when answer is selected, u can store it somewhere.
here is an example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html
I hope this helps!!
精彩评论