homework1- wirthaw

My android app was inspired by the greatest football team ever. I decided to make a green bay packers trivia app.

For now the app only has 5 programmed questions but more questions could easily be added. The game play is a question is asked, the player selects their answer and the program determines whether it is right or wrong. Your score is held and at the end of the game you are shown the number correct out of the total questions. The layout is very straight forward and one button per screen makes everything flow very smoothly.

As for the code, I did a couple of unique things. First, I used a viewSwitcher to alternate between an answerView and a questionView. Rather than use two totally separate views this allows one view (which i called game view) but seperate layouts in that view that can be easily switched between using showNext or showPrevious. To implement this all i had to do was add a view switcher tag to the game XML which looked liked this

<?xml version=”1.0″ encoding=”utf-8″?>
<ViewSwitcher
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:id=”@+id/viewSwitcher1″
android:layout_height=”fill_parent”
android:background=”@drawable/packerbg”></ViewSwitcher>

In betweenthe viewSwitcher tags I simply added two <LinearLayout> and the viewSwitcher automatically handles the rest

Second, I added a packer background. This was really easy and you can actually see what i did in the above code. I saved a packer image i made in each of the resource folders than added android:background = “@drawable/packerbg” into the ViewSwitcher tag.

Third, I added text to speech into the program. The text to speech reads the question and it says correct or incorrect accordingly on the answer screen. I thought this was going to be a lot harder to implement than it was. After implementing the oninitlistener and importing its methods in my activity I just newed a TextToSpeech object called talker which needed on onitlistener and a context, “this “satisfied both arguments.

talker = new TextToSpeech(this,this);

Then to get the talker to talk you call the speak method like this

talker.speak(s, TextToSpeech.QUEUE_ADD, null);

Last, I used preferences to save the game so if you receive a phone call in the middle of the game or you flip the phone you can pick up on the same question where you left off.

 

 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *