From 420d97fbc8eb573c1e200e9d3d46668b00990e7a Mon Sep 17 00:00:00 2001
From: Ricardo Cervera
Open the activity_main.xml
file from the res/layout/
+
Open the fragment_main.xml
file from the res/layout/
directory.
Note: In Eclipse, when you open a layout file, you’re first shown the Graphical Layout editor. This is an editor that helps you build layouts using WYSIWYG tools. For this -lesson, you’re going to work directly with the XML, so click the activity_main.xml tab at +lesson, you’re going to work directly with the XML, so click the fragment_main.xml tab at the bottom of the screen to open the XML editor.
The BlankActivity template you chose when you created this project includes the
-activity_main.xml
file with a {@link
+fragment_main.xml
file with a {@link
android.widget.RelativeLayout} root view and a {@link android.widget.TextView} child view.
First, delete the {@link android.widget.TextView <TextView>} element and change the {@link
@@ -95,7 +95,6 @@ android:orientation} attribute and set it to "horizontal"
.
The result looks like this:
-<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" diff --git a/docs/html/training/basics/firstapp/creating-project.jd b/docs/html/training/basics/firstapp/creating-project.jd index 9516e37..50485db 100644 --- a/docs/html/training/basics/firstapp/creating-project.jd +++ b/docs/html/training/basics/firstapp/creating-project.jd @@ -120,8 +120,8 @@ devices. Finish. --Your Android project is now set up with some default files and you’re ready to begin -building the app. Continue to the next lesson.
+Your Android project is now a basic "Hello World" app that contains some default files. +To run the app, continue to the next lesson.
@@ -155,8 +155,8 @@ and replace projects. -Your Android project is now set up with several default configurations and you’re ready to begin -building the app. Continue to the next lesson.
+Your Android project is now a basic "Hello World" app that contains some default files. +To run the app, continue to the next lesson.
Tip: Add the
diff --git a/docs/html/training/basics/firstapp/running-app.jd b/docs/html/training/basics/firstapp/running-app.jd index 999d399..23cedba 100644 --- a/docs/html/training/basics/firstapp/running-app.jd +++ b/docs/html/training/basics/firstapp/running-app.jd @@ -62,7 +62,7 @@ href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code andro attributes. For your first app, it should look like this:platform-tools/
as well as thetools/
directory to yourPATH
environment variable.<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> + <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> ... </manifest>diff --git a/docs/html/training/basics/firstapp/starting-activity.jd b/docs/html/training/basics/firstapp/starting-activity.jd index 712eabc..9aa25a3 100644 --- a/docs/html/training/basics/firstapp/starting-activity.jd +++ b/docs/html/training/basics/firstapp/starting-activity.jd @@ -45,7 +45,7 @@ starts a new activity when the user clicks the Send button.Respond to the Send Button
-To respond to the button's on-click event, open the
activity_main.xml
+To respond to the button's on-click event, open the
@@ -73,14 +73,6 @@ public void sendMessage(View view) { }fragment_main.xml
layout file and add the {@code android:onClick} attribute to the {@link android.widget.Button <Button>} element:
This requires that you import the {@link android.view.View} class:
--import android.view.View; -- -
Tip: In Eclipse, press Ctrl + Shift + O to import missing classes -(Cmd + Shift + O on Mac).
-In order for the system to match this method to the method name given to {@code android:onClick}, the signature must be exactly as shown. Specifically, the method must:
@@ -111,6 +103,14 @@ an activity called {@code DisplayMessageActivity}: Intent intent = new Intent(this, DisplayMessageActivity.class); +This requires that you import the {@link android.content.Intent} class:
++import android.content.Intent; ++ +
Tip: In Eclipse, press Ctrl + Shift + O to import missing classes +(Cmd + Shift + O on Mac).
+The constructor used here takes two parameters:
Note:
-You now need import statements for android.content.Intent
-and android.widget.EditText
. You'll define the EXTRA_MESSAGE
-constant in a moment.
android.widget.EditText
.
+You'll define the EXTRA_MESSAGE
constant in a moment.
An {@link android.content.Intent} can carry a collection of various data types as key-value pairs called extras. The {@link android.content.Intent#putExtra putExtra()} method takes the @@ -165,7 +164,7 @@ public constant. So add the {@code EXTRA_MESSAGE} definition to the top of the { MainActivity} class:
-public class MainActivity extends Activity { +public class MainActivity extends ActionBarActivity { public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; ... } @@ -223,6 +222,7 @@ work.
PlaceholderFragment
class that extends
+{@link android.app.Fragment}. You will not need this class in the final version of this
+activity.Because the {@link android.app.ActionBar} APIs are available only on {@link -android.os.Build.VERSION_CODES#HONEYCOMB} (API level 11) and higher, you must add a condition -around the {@link android.app.Activity#getActionBar()} method to check the current platform version. -Additionally, you must add the {@code @SuppressLint("NewApi")} tag to the -{@link android.app.Activity#onCreate onCreate()} method to avoid lint errors.
+Fragments decompose application functionality and UI into reusable modules. For more +information on fragments, see the Fragments +API Guide. The final version of this activity does not use fragments.
The {@code DisplayMessageActivity} class should now look like this:
-public class DisplayMessageActivity extends Activity { +public class DisplayMessageActivity extends ActionBarActivity { - @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); - // Make sure we're running on Honeycomb or higher to use ActionBar APIs - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - // Show the Up button in the action bar. - getActionBar().setDisplayHomeAsUpEnabled(true); + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .add(R.id.container, new PlaceholderFragment()).commit(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - NavUtils.navigateUpFromSameTask(this); + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + + public PlaceholderFragment() { } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_display_message, + container, false); + return rootView; + } + } }@@ -422,7 +438,7 @@ public void onCreate(Bundle savedInstanceState) {
That's it, you've built your first Android app!
-- cgit v1.1