|
package com.eoeAndroid.book.ex07_widget;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ex07_Widget extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
find_and_modify_button();
}
private void find_and_modify_button()
{
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(button_listener);
}
private Button.OnClickListener button_listener = new Button.OnClickListener()
{
public void onClick(View v)
{
setTitle("哎呦,button被点了一下");
}
};
}
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout> |
|