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?

More than 5 years have passed since last update.

[Android][Java] Button #1

Last updated at Posted at 2015-04-28

生成

WidgetsからButtonを選んで配置。
android_button.JPG

これによって追加されたコード

activity_main.xml
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true" />

押されたら

プロパティのonClickを見てみると何やら2つ出てくる。
android_button2.JPG

  • setListFooter
  • setContentView

よく分からないので、とりあえずこれは無視して自分でメソッドを作る。

MainActivity.java
public void onClick(View view) {
    System.out.println("[onClick] view="+view);
}

これでプロパティのonClickに作成したメソッドが表示されるようになるので、選択すると以下のコードが追加される。

activity_main.xml
<Button
    (中略)
    android:onClick="onClick" />

実行してボタンを押すと、

logcat
I/View﹕ Touch down dispatch to android.support.v7.internal.widget.TintButton{421ddea0 VFED..C. ........ 272,511-448,607 #7f090040 app:id/button}, event = (以下略)
I/View﹕ Touch up dispatch to android.support.v7.internal.widget.TintButton{421ddea0 VFED..C. ...P.... 272,511-448,607 #7f090040 app:id/button},  event = (以下略)
I/System.out﹕ [onClick] view=android.support.v7.internal.widget.TintButton{421ddea0 VFED..C. ...P.... 272,511-448,607 #7f090040 app:id/button}

ToDo

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?