###前提・実現したいこと
Intent を使って画面を変えて動作させたい。
###発生している問題・エラーメッセージ
調べてその通りにやっても画面も変わりませんし、動作もしません。
原因がわかりません。
###該当のソースコード
mainfest
XML
1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="numa.jyanken"> 4 5 <application 6 android:allowBackup="true" 7 android:icon="@drawable/icon" 8 android:label="@string/app_name" 9 android:roundIcon="@drawable/icon" 10 android:supportsRtl="true" 11 android:theme="@style/AppTheme"> 12 <activity android:name=".JyankenActivity" 13 android:label="@string/app_name"> 14 <intent-filter> 15 <action android:name="android.intent.action.MAIN" /> 16 17 <category android:name="android.intent.category.LAUNCHER" /> 18 </intent-filter> 19 </activity> 20 <activity 21 android:name=".KekkaActivity" 22 android:label="@string/app_name"> 23 </activity> 24 </application> 25 26</manifest>
JyankenActivity
Java
1package numa.jyanken; 2 3 import android.app.Activity; 4 import android.content.Intent; 5 import android.support.v7.app.AppCompatActivity; 6 import android.os.Bundle; 7 import android.view.View; 8 import android.view.animation.Animation; 9 import android.view.animation.AnimationSet; 10 import android.view.animation.TranslateAnimation; 11 import android.widget.Button; 12 import android.widget.ImageButton; 13 import android.widget.ImageView; 14 import android. 15 widget.TextView; 16 17 import java.util.Random; 18 19public class JyankenActivity extends Activity{ 20 21 @Override 22 protected void onCreate(Bundle savedInstanceState) { 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.jyanken_main); 25 ImageButton btn = (ImageButton) findViewById(R.id.button); 26 btn.setOnClickListener(new View.OnClickListener() { 27 @Override 28 public void onClick(View v) { 29 setContentView(R.layout.anime); 30 31 TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 100, -100); 32 translateAnimation.setRepeatMode(Animation.REVERSE); 33 translateAnimation.setRepeatCount(5); 34 translateAnimation.setDuration(300); 35 ImageView imageView = (ImageView) findViewById(R.id.imageView3); 36 37 TranslateAnimation translateAnimation2 = new TranslateAnimation(0, 0, -100, 100); 38 translateAnimation2.setRepeatMode(Animation.REVERSE); 39 translateAnimation2.setRepeatCount(5); 40 translateAnimation2.setDuration(300); 41 ImageView imageView2 = (ImageView) findViewById(R.id.imageView4); 42 43 44 translateAnimation.setAnimationListener(new Animation.AnimationListener() { 45 46 @Override 47 public void onAnimationStart(Animation animation) { 48 49 } 50 51 @Override 52 public void onAnimationEnd(Animation animation) { 53 gu(); //ここで処理させます 54 } 55 56 @Override 57 public void onAnimationRepeat(Animation animation) { 58 59 } 60 61 }); 62 63 64 imageView.startAnimation(translateAnimation); 65 imageView2.startAnimation(translateAnimation2); 66 67 68 } 69 70 71 } ); 72 73} 74 //ここです 75 public void gu() { 76 77 Intent intent = new Intent(); 78 intent.setClassName("numa.jyanken.JyankenActivity","numa.jyanken.KekkaActivity") 79 startActivity(intent); 80 } 81 82} 83
KekkaActivity
Java
1package numa.jyanken; 2 3import android.app.Activity; 4import android.os.Bundle; 5import android.widget.ImageView; 6import android.widget.TextView; 7 8/** 9 * Created by user on 2017/04/26. 10 */ 11 12public class KekkaActivity extends Activity { 13 14 @Override 15 protected void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 setContentView(R.layout.kekka); 18 final ImageView imageView1 = (ImageView) findViewById(R.id.imageView); 19 imageView1.setImageResource(R.drawable.gu); 20 Dousa dousa = new Dousa(); 21 final TextView textview = (TextView) findViewById(R.id.textView1); 22 final TextView textview2 = (TextView) findViewById(R.id.textView2); 23 final TextView textview3 = (TextView) findViewById(R.id.textView3); 24 25 int Myplayer = 0; 26 int Youplayer = dousa.player[1]; 27 int Myhand = R.string.gu; 28 int Hikiwake = R.string.hikiwake; 29 int Lose = R.string.lose; 30 int Win = R.string.win; 31 int Youhand = dousa.hand; 32 33 dousa.judge(); 34 if (Myplayer - Youplayer == 0) { 35 final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2); 36 imageView2.setImageResource(R.drawable.gu); 37 textview2.setText(Myhand); 38 textview3.setText(Youhand); 39 textview.setText(Hikiwake); 40 } else if (Myplayer - Youplayer == -2) { 41 final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2); 42 imageView2.setImageResource(R.drawable.pa); 43 textview2.setText(Myhand); 44 textview3.setText(Youhand); 45 textview.setText(Lose); 46 } else if (Myplayer - Youplayer == -1) { 47 final ImageView imageView2 = (ImageView)findViewById(R.id.imageView2); 48 imageView2.setImageResource(R.drawable.cyoki); 49 textview2.setText(Myhand); 50 textview3.setText(Youhand); 51 textview.setText(Win); 52 } 53 54 } 55} 56
//ここです というところでIntentを設定しています。
//ここで動作させます というところでgu()を呼び出しています。
他にも必要なソースがございましたら追記いたします。
よろしくお願いいたします。
###補足情報(言語/FW/ツール等のバージョンなど)
Androidstudio2.3
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/26 13:24
2017/04/26 13:32
退会済みユーザー
2017/04/26 13:40
退会済みユーザー
2017/04/26 13:43
2017/04/26 13:47
退会済みユーザー
2017/04/26 13:51
退会済みユーザー
2017/04/26 13:54
退会済みユーザー
2017/04/26 13:55
2017/04/26 14:00 編集
退会済みユーザー
2017/04/26 14:18 編集
2017/04/26 14:34
2017/04/26 16:01
退会済みユーザー
2017/04/26 23:50
2017/04/27 00:02
退会済みユーザー
2017/04/27 06:46
2017/04/27 07:21
退会済みユーザー
2017/04/27 08:06 編集
2017/04/27 08:00
退会済みユーザー
2017/04/27 08:13
2017/04/27 08:18
退会済みユーザー
2017/04/29 06:30
2017/04/29 08:40
退会済みユーザー
2017/04/29 13:35
退会済みユーザー
2017/04/29 14:02
退会済みユーザー
2017/04/29 14:14