我想从activity B中获取信息,然后传到activity A 中,问题是我获得的值是null。我的代码显示是你点击过多少次按钮然后把值返回到第一个Activity,的确应该是这个样子的。
我贴出代码,大家看看哪里出错了?
returned.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Next.this, Hw3Activity.class);
intent.putExtra("text", counted.getText().toString());
startActivity(intent);
/*Next is the current activity, Counted is the name of my text box*/
}
});
click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
}
这是我想把信息传递到的 Activity:
Button change;
TextView text;
int number;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
change = (Button) findViewById(R.id.change);
text = (TextView) findViewById(R.id.count);
String s1 = getIntent().getStringExtra("Textview01");
text.setText("You clicked the button " + s1 + " times.");
change.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Next.class);
startActivityForResult(intent, 0);
/*this button is for going to the 2nd activity,not my problem currently*/
}
});
}
}