最終更新:2015-12-29 (火) 14:06:51 (3012d)
Android/ボタン
http://developer.android.com/reference/android/widget/Button.html
継承
Activityでレイアウトの読み込み
- Activity.setContentView(R.layout.activity_xxx)
クリックの処理
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 }
種類
android.widget.Button 通常のボタン android.widget.ToggleButton トグルボタン android.widget.ImageButton? イメージを表示できるボタン android.widget.CheckBox? チェックボックス android.widget.RadioButton? ラジオボタン