3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android Studio】【Java】ボタンによる画面遷移

Last updated at Posted at 2020-01-31

あくまでも自分用のmemoとして残しておきます。

必要なファイル(全4つ)

・MainActivity.java
・activity_main.xml
・SubActivity.java
・activity_sub.xml

MainActivity.javaのソースコード

17~24行目を追加

スクリーンショット 2020-01-31 21.56.09.png
Button nextButton = findViewById(R.id.bt_next);
nextButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getApplication(),SubActivity.class);
        startActivity(intent);
    }
});

SubActivity.javaのソースコード

16~22行目を追加

スクリーンショット 2020-01-31 21.56.46.png
Button backButton = findViewById(R.id.bt_back);
backButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        finish();
    }
});

activity.xml(デザインタブ)

画面右上のidに注意!

スクリーンショット 2020-01-31 21.57.19.png

activity_sub.xml(デザインタブ)

画面右上のidに注意!

スクリーンショット 2020-01-31 21.57.29.png
3
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?