I want to pass the variables year, month, and day to another Activity.
How can I do that?
Button button;
int year_x,month_x,day_x;
static final int DIALOG_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Calendar cal = Calendar.getInstance();
year_x = cal.get(Calendar.YEAR);
month_x = cal.get(Calendar.MONTH);
day_x = cal.get(Calendar.DAY_OF_MONTH);
showDialogOnButtonClick();
}
public void showDialogOnButtonClick(){
button = (Button)findViewById(R.id.button);
button.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DIALOG_ID);
}
}
);
}
@Override
protected Dialog onCreateDialog(int id){
if(id == DIALOG_ID)
return new DatePickerDialog(this,dpickerListner,year_x,month_x,day_x);
return null;
}
private DatePickerDialog.OnDateSetListener dpickerListner
= new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
year_x = year;
month_x = monthOfYear + 1;
day_x = dayOfMonth;
Toast.makeText(MainActivity.this,year_x +"/"+ month_x+"/"+day_x,Toast.LENGTH_LONG).show();
}
};
This is how I start the Activity which shows a CalendarView and DatePicker
public void onButtonClick(View view){
if(view.getId()==R.id.button2)
{
Intent i = new Intent(MainActivity.this,CalendarView.class);
startActivity(i);
}
}
}