



public class ButtonClickListener implements OnClickListener{
private Context context;
ButtonClickListener(Context c){
context = c;
}
public void onClick(View v) {
Toast.makeText(
context.getApplicationContext(),
"ボタンが押されました",
Toast.LENGTH_LONG).show();
}
}
public class AndroidsCastleActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.sampleButton);
btn.setOnClickListener( new ButtonClickListener(this) );
}
}

Portions of this page are modifications
based on work created and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution License.
- Remical Soft -