我試圖從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