Skip to content

Commit

Permalink
Lesson 4
Browse files Browse the repository at this point in the history
  • Loading branch information
atuyan39 committed May 8, 2021
1 parent ef9363d commit 251756d
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Expand Up @@ -12,13 +12,15 @@
<activity android:name=".MainActivity" />
<activity android:name=".Lesson1Activity" />
<activity android:name=".Lesson2Activity" />
<activity android:name=".Lesson3Activity">
<activity android:name=".Lesson3Activity" />
<activity android:name=".Lesson4Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Lesson4SubActivity" />
</application>

</manifest>
66 changes: 66 additions & 0 deletions app/src/main/java/com/example/Lesson4Activity.java
@@ -0,0 +1,66 @@
package com.example;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class Lesson4Activity extends AppCompatActivity {
private final String TAG = "DEBUG_" + Lesson4Activity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
setContentView(R.layout.activity_lesson4);

// Viewを取得
Button button = findViewById(R.id.lesson4_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Lesson4SubActivity.class);
startActivity(intent);
}
});
}

@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart");
}

@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart");
}

@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}

@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy");
}
}
64 changes: 64 additions & 0 deletions app/src/main/java/com/example/Lesson4SubActivity.java
@@ -0,0 +1,64 @@
package com.example;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class Lesson4SubActivity extends AppCompatActivity {
private final String TAG = "DEBUG_" + Lesson4SubActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
setContentView(R.layout.activity_lesson4_sub);

// Viewを取得
Button button = findViewById(R.id.lesson4_sub_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}

@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart");
}

@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart");
}

@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume");
}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause");
}

@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy");
}
}
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_lesson4.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Lesson4Activity">

<TextView
android:id="@+id/lesson4_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lesson4_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/lesson4_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lesson4_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
28 changes: 28 additions & 0 deletions app/src/main/res/layout/activity_lesson4_sub.xml
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Lesson4SubActivity">

<TextView
android:id="@+id/lesson4_sub_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lesson4_sub_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/lesson4_sub_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/lesson4_sub_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -16,4 +16,7 @@
<item>土曜日</item>
<item>日曜日</item>
</string-array>
<!-- Lesson4 -->
<string name="lesson4_text">メイン画面です</string>
<string name="lesson4_sub_text">サブ画面です</string>
</resources>

0 comments on commit 251756d

Please sign in to comment.