package com.example.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestActivity extends Activity {
int a=0;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Button test=(Button) findViewById(R.id.neibulei);
test.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=5;
new hhh().getnum();//调用改代码后,log打印出的a=0;因为重新 new 了一个TestActivity对象,参数均被初始化。
}
});
}
public static class hhh{
public void getnum(){
Log.i("czk","a="+new TestActivity().a);
}
}
}