Developing MyQuiz Apps Part 1
Using ADT 18 On Win 7
Save the following image as icon.png
Go to Menu. Select File/New/Android Application Project.
Application Name: My Quiz
Project Name: MyQuiz
Package Name: com.example.myquiz
Accept default and click Next.
Browse for the icon image that you have saved in Step 0.
Accept default and click Next.
Activity Name: QuizSplashActivity
Layout Name: splash
Click Finish.
2.1) Select the file QuizSplashActivity.java.
2.2) Go to Menu. Select Edit/Copy.
2.3) Go to Menu. Select Edit/Paste.
2.4) Type Quiz Activity.
Besides using command menu to perform Copy/Paste task, you can also use command keys ie CTRL+C/CTRL+V to achieve the same effect. |
2.5) Observe Package Explorer.
(QuizActivity.java should appear in the src folder under com.example.myquiz sub-folder)
Replace the content of the file with the following codes.
package com.example.myquiz; import android.app.Activity; public class QuizActivity extends Activity { public static final String GAME_PREFERENCES = "GamePrefs"; } |
File name: MyQuiz/src/com.example.myquiz/QuizActivity.java
Replace the content of the file with the following codes.
package com.example.myquiz; import android.os.Bundle; public class QuizSplashActivity extends QuizActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); } } |
File name: MyQuiz/src/com.example.myquiz/QuizSplashActivity.java
Note that we extend QuizSplashActivity from QuizActivity Class. Therefore we do not need to import android.app.activity anymore. QUizSplashActivity automatically contains GAME_PREFERENCES as its data. |
QuizSplashActivity.java doesn’t require menu layout. Therefore, delete the quiz_splash.xml.
Copy and Paste QuizSplashActivity.java as…
QuizMenuActivity
QuizHelpActivity
QuizScoresActivity
QuizSettingsActivity
QuizGameActivity
6.1) Create a folder drawable under res folder.
6.2) Save the following image as bckgrnd.jpg under drawable folder.
Replace the content of the following files
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bckgrnd"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/splash" /> </RelativeLayout> |
File name: MyQuiz/res/layout/splash.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">MyQuiz</string> <string name="splash">SPLASH</string> <string name="help">HELP</string> <string name="menu">MENU</string> <string name="settings">SETTINGS</string> <string name="game">GAME</string> <string name="scores">SCORES</string> </resources> |
File name: MyQuiz/res/values/strings.xml
Notice that we have additional string values such as "help", "menu", "settings", "game" are "scores". At the moment these string values are not being used by any layout file. We will use them in the subsequent steps. |
As a result, if you view the file splash.xml using Graphical Layout mode, you will get the following output.
menu.xml
help.xml
scores.xml
settings.xml
game.xml
At the moment you can only see the QuizSplashActivity layout view only.
1) http://developer.android.com/tools/projects/projects-eclipse.html
https://drive.google.com/file/d/0B86b-ALn-1MGY0NUVWM3dVUwYUk/view?usp=sharing