Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Last active Jul 11, 2021
Embed
What would you like to do?
how to set button click event 1-5
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void showMessage(View view) {
if (view.getId() == R.id.btn1) {
Snackbar.make(view, "ボタン1が押されました", Snackbar.LENGTH_SHORT).show();
} else if (view.getId() == R.id.btn2) {
Snackbar.make(view, "ボタン2が押されました", Snackbar.LENGTH_SHORT).show();
}
}
public void deleteMessage(View view) {
Snackbar.make(view, "ボタン3が押されました", Snackbar.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment