I am using Android Studio and have 2 Activities, SearchActivity and RentStartActivity. In my SearchActivity, I have an EditText where a user will click on and it will redirect him to the next Activity. Then in the next Activity, he will select a Date and Time from the CalendarView and TimePicker and when 'Done' Button is clicked, the user will go back to SearchActivity and the Date and Time will be set as a text in the same EditText that he clicked.
Problem is, it returns null.
My code for SearchActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
etRentS = (EditText) findViewById(R.id.etRentS);
etRentS.setFocusable(false);
etRentS.setClickable(true);
etRentS.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent rentS = new Intent(SearchActivity.this, RentStartActivity.class);
startActivityForResult(rentS, 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 1)
{
String date1 = data.getStringExtra("Date1");
String time1 = data.getStringExtra("Time1");
etRentS.setText(date1 + time1);
}
}
And here's my code for RentStartActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rent_start);
calendar1 = (CalendarView) findViewById(R.id.calendar1);
time1 = (TimePicker) findViewById(R.id.time1);
btnDone1 = (Button) findViewById(R.id.btnDone1);
btnDone1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent done1 = new Intent();
done1.putExtra("Date1", calendar1.getDate());
done1.putExtra("Time1", time1.getDrawingTime());
setResult(1, done1);
finish();
}
});
btnCancel1 = (Button) findViewById(R.id.btnCancel1);
btnCancel1.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent cancel1 = new Intent(RentStartActivity.this, SearchActivity.class);
startActivity(cancel1);
}
});
}
Please help and thank you!! :)