Image Buttonを押して表示画面を切り替えたい。
皆さんこんにちは。
ただいま、Androidアプリを作っているのですが任意の画像をAndroid上のボタンとしたくimage buttonで設定し(xml)、MainActivity.ktに指定の別画面へ表示させるようプログラムしたいのですが、幾多の先人の皆様の知恵をお借りしてもエミュレータ上でプログラムが落ちてしまい指定の別画面表示をすることができません。
エラーコード ○○○○_CRS keeps stopping
該当のソースコード
kotlin
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_classes) fun changeActivity(view: View){ val intent = Intent(this, Information::class.java) startActivity(intent) } }
xml
1<activity android:name=".Information"></activity> 2 3AndroidMainfestに追記済み
xml
1 2該当のimage buttonの部分です。 3<LinearLayout 4 android:orientation="horizontal" 5 android:layout_width="412dp" 6 android:layout_height="67dp" 7 app:layout_constraintBottom_toBottomOf="parent" 8 app:layout_constraintLeft_toLeftOf="parent" 9 app:layout_constraintRight_toRightOf="parent" 10 android:baselineAligned="false"> 11 12 <ImageButton 13 android:background="@drawable/partsdesign" 14 android:layout_width="wrap_content" 15 android:layout_height="match_parent" 16 app:srcCompat="@drawable/calender" 17 android:id="@+id/imageButton13" 18 android:layout_weight="0.73" 19 tools:ignore="ContentDescription"/> 20 21 <ImageButton 22 android:background="@drawable/partsdesign" 23 android:layout_width="wrap_content" 24 android:layout_height="72dp" 25 app:srcCompat="@drawable/information" 26 android:id="@+id/imageButton12" 27 android:layout_weight="0.66" 28 android:onClick="changeActivity" 29 tools:ignore="ContentDescription" 30 /> 31 32 <ImageButton 33 android:background="@drawable/partsdesign" 34 android:layout_width="wrap_content" 35 android:layout_height="76dp" 36 app:srcCompat="@drawable/bus" 37 android:id="@+id/imageButton11" 38 android:layout_weight="0.81" 39 tools:ignore="ContentDescription"/> 40 </LinearLayout>
本当はankoを使ってxmlを使わない予定だったのですがankoでやるとエラーが多発したのでxmlにしました。
至らない点あるかとは思いますが、よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/02/13 02:07
2018/02/13 05:01
2018/02/14 16:18 編集