• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/37

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

37 Cards in this Set

  • Front
  • Back

activity

instance of Activity, a class in Android SDK responsible for managing user interaction with a screen of information

In Android, what is a layout made up of?

Definitions written in XML, where each definition is used to create an object that appears on the screen

"reverse DNS" convention

domain name of organization is reversed and suffixed with identifiers --> keeps package name unique

Is it better to create a subclass of Activity called Quiz or QuizActivity?

QuizActivity

What is the recommended formatting for the name of the layout?

reverses order of activity name, all lowercase, underscore between words




ActivityQuiz --> quiz_activity

widget (in relation to Android)

building blocks we'll use to compose user interface. can show text, graphics, interact with user, arrange other widgets.


e.g.: buttons, text input, checkboxes

Every widget is an instance of what class (or one of its subclasses)?

View

Is layout XML validated?

No! Be careful of typos

ViewGroup: What is it? Give an example

ViewGroup: widget that contains and arranges other widgets




Examples: LinearLayout, FrameLayout, RelativeLayout, TableLayout

Set the width of a widget to make the view as big as the parent

android:layout_width="match_parent"

Set the height of a widget to make the view as big as the contents require

android:layout_height="wrap_content"

Add padding

android:padding="24dp"

create a vertical linear layout. create a horizontal linear layout

< LinearLayout android:orientation="horizontal" >


< LinearLayout android:orientation="vertical" >

String resource

string that lives in a strings file (separate xml file). You can hard-code literal strings into your layout xml file, but it's a bad idea. use string resources instead

specify the text in a TextView using a string resource

< TextView android:text="@string/question_text" />

specify the text for the false button in the strings.xml file

< string name="false_button" > False string >

Can you have multiple string files in a project?

Yes, as long as the file is located in res/values/, has a < resources > root element, and contains child string elements

What method is called in the .java file when an instance of the activity subclass is created?

onCreate(bundle)

What does it mean to inflate a layout? What method inflates a layout and puts it on the screen?

Inflate a layout: each widget in the layout file is instantiated as defined by its attributes


Method: public void setContentView(int layoutResID) --> this method is part of the Activity class

resource

piece of the application that is not code: xml files, string files, audio/image files, etc.

resource id for layout for the QuizActivity subclass

R.layout.activity_quiz

Does every widget need a resource ID? How do you generate a resource ID for a true button/widget?

No, not every widget needs a resource ID


To generate, include the android:id attribute in the widget's definition




e.g.


< Button android:id="@+id/true_button"

Android naming convention for instance (member) variable names

mMyVariable




(prepend with m for member variable)

Organizing imports:


shortcut for Mac in Eclipse


shortcut for PC in Eclipse

Mac: Cmd+Shift+O


PC: Ctrl+Shift+O

Three steps to declaring and wiring up widgets

1. Add member variables


2. Get references to the inflated View objects


3. Set listeners on those objects to respond to user actions

Add a member variable for a true button

private Button mTrueButton;

Activity method to get a reference to an inflated widget




Get the reference to the inflated View object for mTrueButton

publiv View getViewById(int id)




mTrueButton = (Button)getViewById(R.id.true_button);





Set a listener to inform you when the true button has been pressed

mTrueButton.setOnClickListener(


new View.OnClickListener(){


@Override


public void OnClick(){


//insert code


}});




implements the OnClickListener Interface

This book uses anonymous inner classes for listeners. What's a trick for remembering the syntax?

Everything within the outermost set of parentheses is passed into .setOnClickListener(OnClickListener)

toast

short message that informs the user of something but does not require any input or action (e.g., a toast providing feedback about whether they got the answer right or wrong)

method to create a toast

public static Toast makeText(Context context, int resId, int duration);

What is the context parameter when making a toast?

typically an instance of Activity

Once you've created a toast, how do you show it on the screen?

Toast.show();

make and show a toast to display an incorrect message in QuizActivity

mTrueButton.setOnClickListener(


new View.OnClickListener(){


@Override


public void onClick(View v){


Toast.makeText(QuizActivity.this, R.string.incorrect_toast, Toast.LENGTH_SHORT).show();


}});



AVD

Android Virtual Device


useful, but a hardware device gives more accurate results

Does Eclipse build projects on command?

No, it builds projects as you modify them

What are two popular tools for building Android apps besides Eclipse?

Maven and ant