: public class MainActivity extends ActionBarActivity {
: ... ... ... ... ... ...
: EditText sname, fname, phone;
: TextView txv;
: protected void onCreate(Bundle savedInstanceState) {
: ... ... ... ...
: sname = (EditText)findViewById(R.id.surname);
: fname = (EditText)findViewById(R.id.firstname);
: phone = (EditText)findViewById(R.id.phone);
: txv = (TextView)findViewById(R.id.txv);
: }
: ... ... ... ... ...
: public void onclick(View v){
: txv.setText(sname.getText().toString() + fname.getText().toString() + "的
: 电话是" + phone.getText());
: }
: }
因为你衍生的类别是ActionBarActivity
所以要用Fragment的做法
但毕竟你还是新手(跟我一样 冏)
我建议你改成衍生 Activity 就好
不然就是在onclick方法里面初始化了
ps1:衍生Activity后 可能会需要更改一些程式码
PS2:你买的书应该是Android App 程式设计教本之无痛起步 (施威铭主编)
因为程式码完全一模一样XD