0
1

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 3 years have passed since last update.

掌田 津耶乃著『Android Jetpack プログラミング』の歩き方(Section3-4) アラートダイアログを利用するのactivity_main.xmlについて補足

Last updated at Posted at 2021-05-07

1. はじめに

 掌田 津耶乃著『Android Jetpack プログラミング』(以下、本書と言う)で勉強しています。この本は、著者が記述しているように入門書ではないようです。それゆえ、本書をしっかりと読み込んでいないと、記載されているソースコード通りに写経しても、エラーで弾かれることがあります。本レポートでは、「『Android Jetpack プログラミング』の歩き方」と題して、掌田 津耶乃著『Android Jetpack プログラミング』の歩き方(Section3-1)に引き続き、ソースコードどうりに写経してアプリが正常に動くようにするための注意点をレポートします。記述や考え方などに誤りがあれば、ぜひご教示いただきたいと思います。

2. 注意点

2.1 リスト3-21のactivity_main.xmlについて、

 本書p188のリスト3-21を写経する際、リスト3-19を元に写経(コピペ?)をすると思いますが、タグの中にある、onClickの行は不要になると思われますので削除しましょう。また、レイアウトが崩れるので、app:layout_constraintTop_toBottomOf="@+id/text1"と変更しましょう。最終的には以下の通りとなると思います。

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
           著作権に配慮して、省略          />

        <!-- 以下、android:onClick="@{(vw) -> obj.doIt(frmNumber, text1)}"を削除 -->
        <!--      app:layout_constraintTop_toBottomOfをtext1に変更 -->
        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="Button"
            android:textSize="18sp"
            app:layout_constraintTop_toBottomOf="@+id/text1"
            tools:layout_editor_absoluteX="0dp" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>


3. 次の記事

Section4-2についても注意点を記述しました。ぜひご参照ください。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?