in an Android app. Activities are Java files where we handle user interactions Layouts - XML files composed of multiple views like Buttons, TextViews, ImageViews, and more
in an Android app. Activities are Java files where we handle user interactions Layouts - XML files composed of multiple views like Buttons, TextViews, ImageViews, and more Listeners - Let’s us ‘listen’ for certain user interactions and interact to them
protected void onCreate(Bundle savedInstanceState) { … findViewById(R.id.flashcard_question).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // do something } }); } In order for our code to be called, we need to put it in the onCreate() method.
protected void onCreate(Bundle savedInstanceState) { … findViewById(R.id.flashcard_question).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // do something } }); } In order for our code to be called, we need to put it in the onCreate() method. onCreate() is called whenever a screen (or Activity) is first shown
Why doesn’t the following work? findViewById(R.id.flashcard_question).setText("a question?”); Not all views have these specific methods, like setText(). Only views that contain text will have the method
setText(). Only views that contain text will have the method ((TextView) findViewById(R.id.flashcard_question)).setText("a question?"); OR TextView flashcardQuestion; @Override protected void onCreate(Bundle savedInstanceState) { ... flashcardQuestion = findViewById(R.id.flashcard_question); flashcardQuestion.setText("a question?”); }
has an "intention" to perform an action. Android uses these Intent objects to specify what it wants to happen (ie : start a new Activity). When an Intent is used, data can also be attached to the Intent so that more information can be given to the 'receiver' of the intent.
“some info to send”); startActivity(intent); ActivityB protected void onCreate(Bundle savedInstanceState) { … String data = getIntent().getStringExtra(“key"); // data = “some info to send”
define a wide range of things (colors, images, layouts, strings). Drawables are a specific type of resource that can be “drawn” onto a screen They can be Bitmap files (created from PNG, JPG or Vector based files) or XML files that we can use as icons or backgrounds for views.
members 2. Ask for TA help Only the Required Features need to be finished and submitted. For submission, you should submit a GIF that shows all the features you implemented