<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="match_parent" android:text="Button"
android:layout_height="wrap_content" android:id="@+id/main_btn1"
android:onClick="buttonClickHandler"/>
<Button android:layout_width="match_parent" android:text="Button"
android:layout_height="wrap_content" android:id="@+id/main_btn2"
android:onClick="buttonClickHandler"/>
</LinearLayout>
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void buttonClickHandler(View target)
{
switch (target.getId())
{
case R.id.main_btn1:
Log.i("btn", "main_btn1");
System.out.println("main_btn1");
break;
case R.id.main_btn2:
Log.i("btn", "main_btn2");
System.out.println("main_btn2");
break;
default:
break;
}
}
}