文本输入findViewById,监听按钮button.setOnClickListener,文本输出setText。
package com.example.gogear777.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;
public class MyActivity extends Activity {
private EditText user = null;
private TextView result = null;
private Button button = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//载入main.xml Layout,此时myTextView:text为hello
setContentView(R.layout.activity_my);
user = (EditText) findViewById(R.id.user);
result = (TextView) findViewById(R.id.result);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
String name = user.getText().toString();
System.out.println(name);
result.setText(name);
}
});
}
}