Created
June 27, 2015 23:17
-
-
Save udacityandroid/0d6a67d340cdf28bbf6e to your computer and use it in GitHub Desktop.
Android for Beginners : Menu Solution Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LinearLayout 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" | |
android:orientation="vertical" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/menu_item_1" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Mango sorbet" | |
android:textAppearance="?android:textAppearanceMedium" /> | |
<TextView | |
android:id="@+id/menu_item_2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:text="Blueberry pie" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:textSize="18sp" /> | |
<TextView | |
android:id="@+id/menu_item_3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:text="Chocolate lava cake" | |
android:textAppearance="?android:textAppearanceMedium" | |
android:textSize="18sp" /> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginTop="8dp" | |
android:onClick="printToLogs" | |
android:text="Print menu to logs" /> | |
</LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
public void printToLogs(View view) { | |
// Find first menu item TextView and print the text to the logs | |
TextView textViewItem1 = (TextView) findViewById(R.id.menu_item_1); | |
String menuItem1 = textViewItem1.getText().toString(); | |
Log.v("MainActivity", menuItem1); | |
// Find second menu item TextView and print the text to the logs | |
TextView textViewItem2 = (TextView) findViewById(R.id.menu_item_2); | |
String menuItem2 = textViewItem2.getText().toString(); | |
Log.v("MainActivity", menuItem2); | |
// Find third menu item TextView and print the text to the logs | |
TextView textViewItem3 = (TextView) findViewById(R.id.menu_item_3); | |
String menuItem3 = textViewItem3.getText().toString(); | |
Log.v("MainActivity", menuItem3); | |
} | |
} |
i was here
guys it doesn not poo up anything
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
java code
package com.example.android.newproject;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
}
xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
it give nothing