我正在尝试将 3 个字符串传递给一个新活动。通过调试,我发现我的变量在我将它们放入附加项时不为空,但当我尝试获取它们时它们为空
calendarView.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth)
{
//Toast.makeText(getApplicationContext(), ""+dayOfMonth, 0).show();
Intent myIntent = new Intent(CalendarActivity.this, DateDayActivity.class);
myIntent.putExtra("year", year);
myIntent.putExtra("month", month);
myIntent.putExtra("dayOfMonth", dayOfMonth);
CalendarActivity.this.startActivity(myIntent);
}
});
这是变量为空的被调用活动:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_date_day);
Bundle extras=getIntent().getExtras();
String year=extras.getString("year");
String month=extras.getString("month");
String dayOfMonth=extras.getString("dayOfMonth");
String date=dayOfMonth+"/"+month+"/"+year;
TextView tv=(TextView)findViewById(R.id.textView1);
tv.setText(date);
}