1、New Android Project->
Project name:Button
Build Target:Android 2.2
Application name:ButtonDemo
Package name:com.b510.textview.activity
Create Activity:MainActivity
Min SDK Version:8
Finish
2、修改MainActivity.java文件
public class MainActive extends Activity { /** Called when the activity is first created. */ private Button button = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActive.this, "你点击了按钮!", Toast.LENGTH_LONG).show(); } }); } }
3、修改main.xml文件
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button1" />