main。xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<EditText
android:id="@+id/et"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:editable="false" //设置是否可编辑。如果它的值为:“true” 怎可以编辑,若“false”怎不可编辑。
android:cursorVisible="false" //设定光标为显示/隐藏,默认显示。
android:textSize="12pt"
/>
<Button
android:id="@+id/bn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="单击我"
/>
</LinearLayout>
java代码
package com.moon;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Fsan001 extends Activity {
/** Called when the activity is first created. */
private EditText et=null;
private Button bn=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et=(EditText) findViewById(R.id.et);
bn=(Button) findViewById(R.id.bn);
bn.setOnClickListener(new MyOnClickListener());
}
class MyOnClickListener implements OnClickListener{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
et.setText("bn被单击了!");
}
}
}