最終更新:2015-12-29 (火) 14:06:51 (3040d)  

Android/ボタン
Top / Android / ボタン

android.widget.Button

http://developer.android.com/reference/android/widget/Button.html

継承

Activityでレイアウトの読み込み

クリックの処理

View.setOnClickListener

  • interface View.OnClickListener
    • メソッド:abstract void onClick(View v)
    final Button button = (Button) findViewById(R.id.button_id);
             button.setOnClickListener(new View.OnClickListener() {
                 public void onClick(View v) {
                     // Perform action on click
                 }
             });

XMLレイアウトでの定義 (android:onClick)

  • However, instead of applying an OnClickListener to the button in your activity, you can assign a method to your button in the XML layout, using the android:onClick attribute. For example:
     <Button
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         android:text="@string/self_destruct"
         android:onClick="selfDestruct" />
  • In order for this to work, the method must be public and accept a View as its only parameter. For example:
     public void selfDestruct(View view) {
         // Kabloey
     }

種類