Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
udacityandroid / MainActivity.java
Created June 27, 2015 23:17
Android for Beginners : Menu Solution Code
package com.example.android.menu;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@udacityandroid
udacityandroid / MainActivity.java
Last active November 22, 2022 21:34
Android for Beginners : Cookies Starting Code
package com.example.android.cookies;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
@udacityandroid
udacityandroid / Code snippet from MainActivity.java
Last active February 6, 2023 14:25
Android for Beginners : Negative Number of Cups of Coffee Extra Challenge Solution
/**
* This method is called when the plus button is clicked.
*/
public void increment(View view) {
if (quantity == 100) {
// Show an error message as a toast
Toast.makeText(this, "You cannot have more than 100 coffees", Toast.LENGTH_SHORT).show();
// Exit this method early because there's nothing left to do
return;
}
@udacityandroid
udacityandroid / TextView.java
Created June 15, 2015 18:23
Android for Beginners : Simplified TextView class
/**
* Displays text to the user.
*/
public class TextView extends View {
// String value
private String mText;
// Text color of the text
private int mTextColor;
@udacityandroid
udacityandroid / Option A
Last active February 7, 2023 13:27
Android Development for Beginners : Calculate the Price Method
/**
* Calculates the price of the order based on the current quantity.
*
* @return the price
*/
private int calculate price(int quantity {
int price = quantity * 5;
return price;
}
@udacityandroid
udacityandroid / Method 1
Last active February 3, 2023 09:49
Android Development for Beginners : Define a Method
private String createCalendarEventReminder(String eventName, String location, int minutesAway) {
String reminder = "You have an upcoming event in " + minutesAway + " minutes.";
reminder = reminder + " It is " + eventName + " held at " + location + ".";
return reminder;
}
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="Guest List"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />