質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

702閲覧

[Android]Intentの画面遷移が機能しない

JanTh1989

総合スコア87

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2019/06/13 03:00

質問内容

Android Studoを使用して、アプリ開発に挑んだのですが、画面遷移が機能してくれません。
各サイトに載っていたものをそのまま入れてみて、Intentクラスを用いた画面遷移を試みましたが、
エミュレータでボタンをクリックしてみても画面が変わりませんでした。
コード(自作部分)に誤りがあるのか、SDKやプロジェクト内の他ファイルに問題があるのかもわかっていません。
解決方法についてご教授の程、お願い致します。

実装コード

※このコードでは、MainActivity⇔NewArrivalActivityの画面遷移を目標にしています。

Java

1//MainActivity.java 2 3package com.example.sampleapplication; 4 5import android.content.Intent; 6import android.support.v7.app.AppCompatActivity; 7import android.os.Bundle; 8import android.view.View; 9import android.widget.Button; 10 11public class MainActivity extends AppCompatActivity{ 12 13 @Override 14 protected void onCreate(Bundle savedInstanceState) { 15 super.onCreate(savedInstanceState); 16 setContentView(R.layout.activity_main); 17 18 Button sendButton = findViewById(R.id.login); 19 sendButton.setOnClickListener(new View.OnClickListener() { 20 @Override 21 public void onClick(View v){ 22 Intent intent = new Intent(getApplication(),NewArrivalActivity.class); 23 startActivity(intent); 24 } 25 }); 26 } 27}

XML

1<!-- activty_main.xml --> 2 3<?xml version="1.0" encoding="utf-8"?> 4<android.support.constraint.ConstraintLayout 5 xmlns:android="http://schemas.android.com/apk/res/android" 6 xmlns:app="http://schemas.android.com/apk/res-auto" 7 xmlns:tools="http://schemas.android.com/tools" 8 android:id="@+id/container" 9 android:layout_width="match_parent" 10 android:layout_height="match_parent" 11 android:paddingBottom="16dp" 12 android:paddingLeft="16dp" 13 android:paddingRight="16dp" 14 android:paddingTop="16dp"> 15 16 <TextView 17 android:text="XXツール" 18 android:textSize="50px" 19 android:layout_width="wrap_content" 20 android:layout_height="wrap_content" 21 android:layout_marginStart="24dp" 22 android:layout_marginTop="210dp" 23 android:layout_marginEnd="24dp" 24 25 android:id="@+id/title" 26 tools:ignore="MissingConstraints" 27 app:layout_constraintEnd_toEndOf="parent" 28 app:layout_constraintStart_toStartOf="parent" 29 app:layout_constraintTop_toTopOf="parent" 30 android:textStyle="bold" 31 android:textColor="#000000"/> 32 33 <EditText 34 android:id="@+id/username" 35 android:layout_width="0dp" 36 android:layout_height="wrap_content" 37 android:layout_marginStart="420dp" 38 android:layout_marginTop="30dp" 39 android:layout_marginEnd="420dp" 40 41 android:hint="ID" 42 android:inputType="text" 43 android:selectAllOnFocus="true" 44 app:layout_constraintEnd_toEndOf="parent" 45 app:layout_constraintStart_toStartOf="parent" 46 app:layout_constraintTop_toBottomOf="@+id/title" android:textSize="24sp"/> 47 48 <EditText 49 android:id="@+id/password" 50 android:layout_width="0dp" 51 android:layout_height="wrap_content" 52 android:layout_marginStart="420dp" 53 android:layout_marginTop="30dp" 54 android:layout_marginEnd="420dp" 55 56 android:hint="パスワード" 57 android:imeActionLabel="Sign in" 58 android:imeOptions="actionDone" 59 android:inputType="textPassword" 60 android:selectAllOnFocus="true" 61 app:layout_constraintEnd_toEndOf="parent" 62 app:layout_constraintStart_toStartOf="parent" 63 app:layout_constraintTop_toBottomOf="@+id/username" android:textSize="24sp"/> 64 65 <Button 66 android:id="@+id/login" 67 android:enabled="false" 68 android:layout_width="wrap_content" 69 android:layout_height="wrap_content" 70 android:layout_gravity="start" 71 android:layout_marginStart="48dp" 72 android:layout_marginEnd="48dp" 73 android:text="ログイン" 74 75 app:layout_constraintBottom_toBottomOf="parent" 76 app:layout_constraintEnd_toEndOf="parent" 77 app:layout_constraintStart_toStartOf="parent" 78 app:layout_constraintTop_toBottomOf="@+id/password" 79 app:layout_constraintVertical_bias="0.1" 80 android:textStyle="bold" 81 android:background="#F44336" 82 android:textColor="#FFFFFF" 83 android:textSize="18sp" 84 android:paddingLeft="25dp" 85 android:paddingRight="25dp"/> 86 87</android.support.constraint.ConstraintLayout>

Java

1//NewArrivalActivity.java 2 3package com.example.equipmentmaintenancetool; 4 5import android.os.Bundle; 6import android.support.v7.app.AppCompatActivity; 7import android.view.View; 8import android.widget.Button; 9 10public class NewArrivalActivity extends AppCompatActivity { 11 12 @Override 13 protected void onCreate(Bundle savedInstanceState) { 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.activity_new_arrival); 16 17 Button returnButton = findViewById(R.id.return_button); 18 returnButton.setOnClickListener(new View.OnClickListener() { 19 @Override 20 public void onClick(View v) { 21 finish(); 22 } 23 }); 24 } 25}

xml

1<!-- acticity_new_arrival.xml --> 2 3<?xml version="1.0" encoding="utf-8"?> 4<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 5 xmlns:app="http://schemas.android.com/apk/res-auto" 6 xmlns:tools="http://schemas.android.com/tools" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 tools:context=".MainActivity"> 10 11 <TextView 12 android:text="遷移先画面" 13 android:textSize="30sp" 14 android:layout_margin="10dp" 15 android:layout_width="wrap_content" 16 android:layout_height="wrap_content" 17 app:layout_constraintBottom_toBottomOf="parent" 18 app:layout_constraintLeft_toLeftOf="parent" 19 app:layout_constraintRight_toRightOf="parent" 20 app:layout_constraintTop_toTopOf="parent" 21 app:layout_constraintVertical_bias="0.3"/> 22 23 <Button 24 android:id="@+id/return_button" 25 android:text="戻る" 26 android:textSize="30sp" 27 android:layout_margin="20dp" 28 android:layout_width="wrap_content" 29 android:layout_height="wrap_content" 30 app:layout_constraintBottom_toBottomOf="parent" 31 app:layout_constraintLeft_toLeftOf="parent" 32 app:layout_constraintRight_toRightOf="parent" 33 app:layout_constraintTop_toTopOf="parent" /> 34 35</android.support.constraint.ConstraintLayout>

xml

1<!-- AndroidManifest.xml --> 2 3<?xml version="1.0" encoding="utf-8"?> 4<manifest xmlns:android="http://schemas.android.com/apk/res/android" 5 package="com.example.equipmentmaintenancetool"> 6 7 <application 8 android:allowBackup="true" 9 android:icon="@mipmap/ic_launcher" 10 android:label="@string/app_name" 11 android:roundIcon="@mipmap/ic_launcher_round" 12 android:supportsRtl="true" 13 android:theme="@style/AppTheme"> 14 <activity android:name=".TroubleReport" /> 15 <activity android:name=".MainActivity"> 16 <intent-filter> 17 <action android:name="android.intent.action.MAIN" /> 18 19 <category android:name="android.intent.category.LAUNCHER" /> 20 </intent-filter> 21 </activity> 22 <activity android:name=".NewArrivalActivity"></activity> 23 </application> 24 25</manifest>

開発環境

・Windows7
・Android Studio 3.4
・仮想デバイス「Nexus 10」

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

あんまりみてないけど、
ログインのボタンに以下設定してるからクリックイベント発生してないんじゃないかな
android:enabled="false"

投稿2019/06/13 05:01

chartreuxx

総合スコア16

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

JanTh1989

2019/06/13 06:37

回答ありがとうございます。 仰る通りでした。 enabledを"true"にするだけで画面遷移できました。 色に変化もなかったため、気づけませんでした。 ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問