0
0

More than 1 year has passed since last update.

App02 確認画面

Last updated at Posted at 2023-04-24

概要

確認ボタンの作成

画面

ファイル名

動作確認

ソースコード

カラー

colors.xml 

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
</resources>

レイアウト

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="確認待ち" />

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="確認中" />

<Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="確認しました" />

    </LinearLayout>

java

MainActivity.java


package com.example.app02;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {   // Activity(画面)のクラスを継承

    private TextView text1;     // TextViewの変数を用意
    private Button btn1;        // Buttonの変数を用意
    private Button btn2;        // Buttonの変数を用意

    @Override   // オーバーライドアノテーション 親クラスのメソッドを上書きしてメソッドを定義するという印
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);         // 親クラス(AppCompatActivity)で定義されたonCreate()を実行
        setContentView(R.layout.activity_main);     // 画面をactivity_mainに設定
        text1 = findViewById(R.id.text1);           // 画面からtext1というIDのViewを探してtext1に代入
        btn1 = findViewById(R.id.btn1);             // 画面からbtn1というIDのViewを探してbtn1に代入
        btn2 = findViewById(R.id.btn2);             // 画面からbtn2というIDのViewを探してbtn2に代入

        btn1.setOnClickListener(new View.OnClickListener() {    // btn1をクリックしたときの処理を設定
            @Override
            public void onClick(View view) {
                text1.setText("確認中");   // text1のテキストを「確認中」に変更
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {    // btn2をクリックしたときの処理を設定
            @Override
            public void onClick(View view) {
                text1.setText("確認しました");    // text1のテキストを「確認しました」に変更
            }
        });
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0