Skip to content

Instantly share code, notes, and snippets.

View Mohanad0's full-sized avatar

Mohanad Naji Salim Mohanad0

View GitHub Profile
@Mohanad0
Mohanad0 / onCreate method in MainActivity.java
Created June 9, 2018 10:00 — forked from udacityandroid/onCreate method in MainActivity.java
Use OnClickListeners for All Categories - onCreate method in MainActivity.java
// Find the View that shows the numbers category
TextView numbers = (TextView) findViewById(R.id.numbers);
// Set a click listener on that View
numbers.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the numbers View is clicked on.
@Override
public void onClick(View view) {
Intent numbersIntent = new Intent(MainActivity.this, NumbersActivity.class);
startActivity(numbersIntent);
@Mohanad0
Mohanad0 / strings.xml
Created June 7, 2018 23:08 — forked from udacityandroid/strings.xml
Android for Beginners : Spanish Localization Solution. This would be saved in the res/values-es/strings.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Title for the application. [CHAR LIMIT=12] -->
<string name="app_name">Sólo Java</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="name">Nombre</string>
<!-- Hint text display in the empty field for the user's name [CHAR LIMIT=20] -->
<string name="toppings">Ingredientes</string>
@Mohanad0
Mohanad0 / Code snippet in SmoothieActivity.java
Created June 7, 2018 15:45 — forked from udacityandroid/Code snippet in SmoothieActivity.java
Android for Beginners : If/Else Smoothie Quiz
int numberOfSmoothiesTillPrize = 10;
if (numberOfSmoothiesTillPrize > 9) {
Log.v("SmoothieActivity", "Congratulations, you get a free smoothie!");
numberOfSmoothiesTillPrize = numberOfSmoothiesTillPrize - 10;
} else {
Log.v("SmoothieActivity", "No free smoothie this time.");
}
Log.v("SmoothieActivity", "You currently have " + numberOfSmoothiesTillPrize + " out of 10 smoothies needed for your next free smoothie.");
@Mohanad0
Mohanad0 / Code snippet in InboxActivity.java
Created June 7, 2018 15:32 — forked from udacityandroid/Code snippet in InboxActivity.java
Android for Beginners : If/Else Email Quiz
int numberOfEmailsInInbox = 0;
int numberOfDraftEmails = 2;
String emailMessage = "You have " + numberOfEmailsInInbox + " emails. ";
String draftMessage = "You have " + numberOfDraftEmails + " email drafts.";
if (numberOfEmailsInInbox == 0) {
emailMessage = "You have no new messages. ";
}
if (numberOfDraftEmails == 0) {
draftMessage = "You have no new drafts.";
@Mohanad0
Mohanad0 / Code snippet in WeatherActivity.java
Created June 7, 2018 15:19 — forked from udacityandroid/Code snippet in WeatherActivity.java
Android for Beginners : If/Else Weather Sample Quiz
boolean isRaining = true;
if (isRaining) {
Log.v("WeatherActivity", "It's raining, better bring an umbrella.");
} else {
Log.v("WeatherActivity", "It's unlikely to rain.");
}
Log.v("WeatherActivity", "Thank you for using the WhetherWeather App.");
@Mohanad0
Mohanad0 / Code snippet in WeatherActivity.java
Created June 7, 2018 15:15 — forked from udacityandroid/Code snippet in WeatherActivity.java
Android for Beginners : If/Else Weather Quiz
boolean isRaining = false;
Log.v("WeatherActivity", "Thank you for using the WhetherWeather App.");
if (isRaining) {
Log.v("WeatherActivity", "It's raining, better bring an umbrella.");
} else {
Log.v("WeatherActivity", "It's unlikely to rain.");
}
@Mohanad0
Mohanad0 / Option A
Created June 3, 2018 22:24 — forked from udacityandroid/Option A
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;
}
@Mohanad0
Mohanad0 / Code snippet from MainActivity.java
Created May 30, 2018 18:22 — forked from udacityandroid/Code snippet from MainActivity.java
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;
}
@Mohanad0
Mohanad0 / activity_main.xml
Created May 29, 2018 23:39 — forked from udacityandroid/activity_main.xml
Android for Beginners : Add the Chocolate Topping Checkbox Solution XML
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@Mohanad0
Mohanad0 / MainActivity.java
Created May 29, 2018 16:54 — forked from udacityandroid/MainActivity.java
Android for Beginners : Cookies Solution Code
package com.example.android.cookies;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {