我试图从Activity
B获取信息到Activity
A,问题是我得到的值由于某种原因返回null
。我的代码看看你点击Button
多少次,然后将值返回到我的第一个Activity
,至少那是它应该做的。如果sombody看到的我的错误,请告诉我,我有类在5个小时:\活动A到活动B返回null的值
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*/
}
});
}
}
我知道了!!这让我走上了正轨。非常感谢! – 2012-02-07 08:40:15
它不会让我接受答案现在,但我会的时候它也允许我:) – 2012-02-07 08:40:40