Put your answer into Piazza.
In the DO NOT USE!!!
version of the initGame
example, which call(s) take so long that they should be called outside the UI thread?
start
initialize
stop
The author makes us very nervous about the mutable Map<String, String> vals
, without telling us how to fix the problem. What fix would work?
clear
in onPostUpdate
clear
at the end of doInBackground
vals.clone()
to execute
What is your opinion about homework 1?
View
and return type void
<Button ... android:text="@string/button_send" android:onClick="sendMessage" />
((Button) findViewById(R.id.button2)).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { ... }});
Intent intent = new Intent(Outerclass.this, ResponseActivity.class);
startActivity(intent)
to start new intent.Context
. Activity
is a subclass of Context
.intent.putExtra(keyString, obj);
onCreate
of new intent:
getIntent().getXXXExtra(keyString)
getXXXExtra
methods.android update project --target 1 --path .(Run
android list targets
to see which target number you need in general.)
android avd &
ant debug install
adb shell am start -n packageName/.MainActivity
adb uninstall packageName
solutions
repo on zoidberg
, and all of you have read permissions. Clone that repo somewhere outside your cs185c
repo. How do you do that?cs185c
directory:
cp -R solutions/workspace/hw01 cs185c/workspace/lab03
lab03
. Then rename the package to edu.sjsu.cs185c.lab03
in the Package Explorer. Also rename the package in AndroidManifest.xml
and change the app name to Lab 3
in strings.xml
. (You should make it a habit to do this whenever you make a new lab or homework assignment.)tabs
into the search box in the top left corner. Click on Text Editors and click on Insert spaces for tabs. But wait, that's not all. Now click on Java/Editor/Typing, then on the Formatter link, and on Edit. Change the name from Eclipse
(default) to CS185C, and change the Tabs poliy to Spaces only. Click on Apply and Ok. Go to MainActivity.java
and select Source → Correct Indentation from the menu. Verify that there are now spaces in the file (by deleting a character in an indented line).
ResponseActivity
with all the default options.MainActivity
, make the first button go to the ResponseActivity
when clicked. How did you do that?ResponseActivity
. Use a for
loop like in the onPostExecute
method.private Question question
to MainActivity
. Change the code in doInBackground
to construct a new Question()
, call read(in)
, and set the question
instance variable. Remove the ArrayList<String>
. Change the return type to Void
and return null
.onPostExecute
so that it gets the question text and choices from the question
object.*
denotes the correct answer.putExtra
to add the question
and the index (0, 1, 2, 3) of the current button to the intent. The latter is a bit tricky. Use this outline:
for (int i = 0; i < buttonIds.length; i++) { final int choiceIndex = i; ((Button) findViewById(buttonIds[i])).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(MainActivity.this, ResponseActivity.class); intent.putExtra("choiceIndex", choiceIndex); ... }}); }
final
, try
intent.putExtra("choiceIndex", choiceIndex)instead. What happens?
getIntExtra
and getSerializableExtra
. Then call
((TextView) findViewById(R.id.responseText)).setText( question.isCorrect(choiceIndex) ? "Good job!" : "Try again!");
export ANT_HOME=/home/user/apache-ant-1.8.4 export PATH=$PATH:$ANT_HOME/bin export ANDROID_HOME=/home/user/adt-bundle-linux-x86/sdk export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
cd cs185c/workspace/lab03 android update project --target 1 --path . android avd &Wait until the emulator as loaded and run
ant debug install