Should I create numerous Activities or make a very long Activity? - android

Okay here, I was told to make a golf score card app, but I'm stuck as how I implement the scoring per holes.
In golf, each hole has its own scoring and the ones I'm making the app for has as much as 27 holes per game.
I don't know whether I should make the 27 Activities for the 27 Holes
or
Use one Activity and ViewFlip with 27 different identical layouts for the whole thing.
Now I just want to know which is the best idea in tackling this problem

I don't know whether I should make the 27 Activities for the 27 Holes or Use one Activity and ViewFlip with 27 different identical layouts for the whole thing.
The layout for each hole is the same(I assume) so make a single activity with that layout and when it's time to go to the next hole score just update the data in that layout. Even if the layouts for different holes are a little different you still should use a single layout that you update(and of course modify it dynamically).
Don't use a ViewFlipper if you plan to flip between 27 identical layouts.

Related

Creating Connect4 in Android

I'm trying to create an Android app to play Connect 4 (Four In A Row, etc). As I'm new to Android dev I created a basic Java application to cope with the logic, which plays connect4 using a 2D array and just uses println to print the array to the console which shows the board.
My question is in my game activity what would be the best way to create a 'board' and have it so I can update it to show the position of counters throughout the game; should I create a canvas object, butcher a table layout, or do something else entirely.
Apologies if this is a silly question; I have very limited Android experience.
Many thanks.
As the board is always the same (4x4) you could use a GridLayout with 4 cols and 4 rows. Put an ImageView in every cell and modify it following the players touches.
Agreed, as 4x4 grid could work if that is what you want since you have limited android experience. You can really make a board/grid in multiple ways. I would suggest making sure you know a little about the UI and the android activity lifecycle before you start diving into something. Eventually you will like to add additional UI elements such as score, player's turn etc.
UI:
http://developer.android.com/guide/topics/ui/index.html
Lifecycle:
http://developer.android.com/training/basics/activity-lifecycle/index.html
Here is a grid tutorial instead of opening another view, just update the one with a piece/color or whatever
GridView tutorial:
http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/

Android Design Decision: one layout for multiple activities?

I am new to Android programming, and I need some advice. I want to create an app that teaches children the alphabet and numbers. I want each letter to have their own screen which you can scroll to and from other letters, but each screen will be similar in that it will have the current letter, pictures of objects that start with that letter, and sounds corresponding with the letter and the objects in the background. Should I make one XML layout for these and somehow changed what letter and objects show up in on the layout using Java, make an XML layout per letter, or is there a way to create a base layout in Java and have all of the letters and numbers inherit these qualities and methods. If that is the case, would that require a Java class per letter as well? I am sorry if these seem like stupid questions, but most of my education in Android has come from internet video tutorials. I appreciate any and all help. Thank you for your help in advance!
v> I want each letter to have their own screen which you can scroll to and from other letters, but each screen will be similar
You probably want to check out ViewPager and Fragments for this.
This website usually seems to have pretty good tutorials. The docs and SO usually have good examples of getting started also.
Note These both require API >= 11 or using a compatibility package which you can find a tutorial Here. so that may be something to take into consideration. If that is an issue then you could simply have one layout with TextView, ImageView, etc... which retrieves its data from a DB and load them when a certain event happens such as a click.
Well, if you want a screen for each of the letters that you could swipe to, but each letter is going to have its own set of properties, I recommend you start looking for a ViewPager with custom Fragments. I think that is a good start. Then, you could focus on some other fancy features like sound.

Android + Is there any Limit to Activities Or XML files?

I have the following requirement:
-----> Showing Five elements of different color and Allow user to select the correct one.
-----> Like that I want to show 16 Kinds(Means 16*5 = 80 elements on 16 Activities)in Random.
===> For that I have created 16 activities and corresponding 16 XML files, and used them Randomly.
&&
First I'l show 5 colors and let the user select one(Say Green), If it is correct, I'l let him select one from another set of 5 colors(This time red)....& so on...Like that I have to make him choose 16 Colors Randomly.And repeat this 16 random colors until he press Back button.That' the exact flow
By the End of the Day, I am in Small Dilemma that, May be there , will be some kind of Logic that winds up the work bit smoothly By reducing the code.
If yes ,Tell me the Logic .
I have all the 80 different elements , to show them in 16 activities, 5 per Activity.
If the elements are the same type, you can have one Activity instead of 16 and choose what to show when creating Activity(or even use Fragments for that).
Any way, you have to be more specific in your question if you want to get complete answer.
Rather than creating 16 different activities, You can create a single activity and 16 different layouts. You can change the layout of activity dynamically and I think it would be good, avoid creating so many activity if there is really no need of it.

Enormous form: how can I do it in Android?

I'm developing an Android Tablet application with Android 3.1 SDK.
I have to implement a form in an Android Tablet. Now I'm doing on one screen with TableLayout, TableRow, TextView, Spinner, buttons, etc.
At this moment I have more than 80 views and then I get a warning about it.
The form is divided into sections and I think I can divide it into tabs but I don't know if I will have the same problem (I'm very new on Android development and now I learning how tabs work).
What do you recommend me? I will have, probably, 160 view or more.
I recommend that you split this huge form into multiple screens / steps somehow, it seems much more useable and managable to me. You could use fragments to hold the steps, and use some paging mechanism to navigate between these fragments. By switching fragments and saving their state you can keep the number of Views on the screen relatively low.
Check out the ViewPager component for this to navigate between fragments by swiping. Or you may use the plain old button based navigation (next/previous step e.g.).
If you really need to display all the form elements on one screen and want to keep the number of instantiated Views, you may be able to do this by using the virtualizing ListView, though it seems quite awkward to me. ListView constructs the rows as needed during scrolling, and you need to tell its adapter that you have X type of rows where X is the number of form-parts.
Why don't you logically break this Enormous form and using something like a Next button show the form in multiple activities. This would keep the screen clean, won't bombard the user with too much of information and finally won't give the warning of excess views on screen.

Different activities or same activity but different layout

I'm working on an app where basically i have X different activities but everyone has a layout equals to the rest. To let you understand better let me do an example:
Suppose i have a game where you have to guess 10 words each level, and I have 5 levels, basically I have in every view 10 question.
So is better to have 5 different activities or only one activity and 5 layouts, one for every level ?
Looking around on the web i did not find a good answer, someone told that Android is based on activity, so 10 different ones is the way to go, but was only a guessing, nothing technical.
Don't make 10 Activities. Don't make 5 layouts. All questions look the same except for the text, right? Don't Repeat Yourself.
Simplify your life reuse the same Activity and Layout for every single question.
When you start the activity, you can pass in data using the .putExtra() methods. Use that to pass in the things that change, like the question text, the correct answer, and the current level.
I would do 1 layout and then program the levels onto it.
Doing a brick breaker game, or tetris, or puzzle game wouldnt want you to have a million diff activity options, but more like 1 layout and 1 activity will populate accordingly.
Usually you can do something like
[home] -> {play, options, exit}
[play] -> {new game, level select}
[options] -> ....derp...
[exit] -> ....derp...
[newgame] --> start activityA where level = 1
[level select] -> click a link which will start activityA with a level = selected.
1 activity which will spawn your information safe and nicely... far far better imo.

Categories

Resources