package com.example.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button button = MainActivity.this.findViewById(R.id.button2); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("lightbox", "クリックされました(setOnClickListener)"); Toast.makeText(MainActivity.this, "ようこそ", Toast.LENGTH_LONG).show(); } }); } public void my_event(View v) { Log.i("lightbox", "クリックされました"); Toast.makeText(this, "ようこそ", Toast.LENGTH_LONG).show(); } }