Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 27, 2014 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nein37/3302d4417976fe3f8dc1 to your computer and use it in GitHub Desktop.
Save nein37/3302d4417976fe3f8dc1 to your computer and use it in GitHub Desktop.
トグルボタンの実装 ref: http://qiita.com/nein37/items/850824d2b35663111ddb
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
CompoundButton toggle = (CompoundButton)findViewById(R.id.compoundButton);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// 状態が変更された
Toast.makeText(MyActivity.this, "isChecked : " + isChecked, Toast.LENGTH_SHORT).show();
}
});
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<Switch
android:id="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment