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

Androidアプリ初心者がハマった

Posted at

Androidをお勉強してたら謎が

ChatGPTに先生になってもらって、実機デバッグの仕方を勉強していた時の話。
ど素人なのでボタンタップのブレークポイントとか基本的なところを学習するためにサンプルコードを生成してくれとお願いしたところ、下記のxmlコードをくれた(MainActivity.ktもくれたけどk)。

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="16dp">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false"
        android:text="Hello World!" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="メッセージを表示" />

</LinearLayout>

ChatGPT先生のおかげで実機デバッグっぽくブレークポイントも動作して感動し、ボタンタップイベントも試せるコードだったのでボタンを押してみたが何も反応しない、タップ時にボタン色が反転するリアクションもない。
いろいろやっていると、
・もう一つボタンを追加すると動作する
・textViewとボタンをxmlで上下入れ替えると動作する
・layout_heightを固定値指定すると動作する
という感じだった。
理由をChatGPTさんにしつこく聞いたけどZが~とか、clickableが~とか、いろいろ教えてくれたがどれも上記の状態が説明できず。。。

初心者としては他にやることがいっぱいあるので一旦あきらめて、このメモを残すことにした。
きっといつか理解できるときがくるんだと信じて。

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