`
public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
AndroidManifest.xml
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
res/layout
directoryonCreate
method:
setContentView(R.layout.activity_main);
res/values/strings.xml
res/values-fr/strings.xml
<TextView ... android:text="@string/app_greeting"/>
res/drawable
<ImageView ... android:src="@drawable/spirit_icon"/>
res/drawable-xhdpi/spirit-icon.jpg
What are the most feared words in the English language?
gradlew
into the root of your project./gradlew assembleDebug
emulator -list-avds emulator -avd Nexus_4_API_16 & adb install -r app/build/outputs/apk/app-debug.apk adb shell am start -n "edu.sjsu.cs151.myapplication/.MainActivity"
TextView
text declaratively.
<TextView ... android:text="Fred">
<TextView ... android:text="@string/protagonist">
android:id="@+id/result"
R.id.result
in Java code
TextView t = (TextView) findViewById(R.id.questionText); t.setText("How old is Fred?");
Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { ... }});
final
if the listener accesses themandroidLab/screen2.png
via Gitsrc/main/res/drawable
directory of the app, e.g.
cp ~/Downloads/sjsu_logo.jpg ~/AndroidStudioProjects/MyApplication/src/main/res/drawables
ImageView
in the layout below the greeting<ImageView ...>
element:
android:src="@drawable/sjsu_logo"You can either edit the XML text or set the
src
property in the property window.
QuizApp
. When you set up the app, make sure the package is set to edu.sjsu.cs151.quizapp
.questionText
and resultText
. That's best done in the property sheet because then Android Studio will rename all references. Rename the buttons trueButton
and falseButton
.questionText
, resultText
, trueButton
, and falseButton
. Initialize them by looking up the component by ID.final TrueFalseQuestion q1 = new TrueFalseQuestion("Was the iPhone the most popular smartphone in 2006?", false); questionText.setText(q1.getText());
trueButton
and falseButton
.resultText
to “Correct” or “Incorrect”.res/values/strings.xml
and add a string named app_greeting
."@string/app_greeting"
strings.xml
and locate the link to the translations editor. Click it. Locate the globe icon in the upper left corner. Pick some language that you know. Provide the translation of “Hello, World!”app_name
.