Listener 사용 - 2014.03.18 강의내용
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button _btnNum;
Button _btnName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_btnNum = (Button) findViewById(R.id.btn_num);
_btnName = (Button) findViewById(R.id.btn_name);
OnClickListener mClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_num:
Toast.makeText(MainActivity.this, "2010211878",
Toast.LENGTH_LONG).show();
break;
case R.id.btn_name:
Toast.makeText(MainActivity.this, "Kim Yeong-Jun",
Toast.LENGTH_LONG).show();
break;
}
}
};
_btnNum.setOnClickListener(mClickListener);
_btnName.setOnClickListener(mClickListener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}