-2

I see in some applications, I can choose a date and write some data there. I can see that added this data into the graphic on another page(or activity).

For instance, I can choose the date:09/09/2017 and number:5 etc. When I open graph page, I can see both of them.

I am asking that how can I pass the date? or how can I match the same date between two different page?

(actually, I want to use CalendarView in android studio and when I select a date, I should pass data into my timestamp which I use in android studio.)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
BatuZ
  • 1
  • 4
  • 1
    You should edit your question there is lot of confusion in your question, All you need is to ask how to pass data from one page to another and access that data on 2nd page. simple as that. else your question will get -ve votes – khan Sep 09 '17 at 13:59

2 Answers2

1

You can pass data from one activity to another by using intent extras,suppose you have an edittext in which you input the date. Store this value to some variable like

String dateFromEdittext=editText.getText().toString();

Now, on button click to next activity, pass the value as extra

 button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
          Intent intent = new Intent(YourActivity.this, NextActivity.class);
          intent.putExtra("date", date);
          startActivity(intent);
 }
    });

Now in your NextActivity, get the date value like

String date=date = getIntent().getStringExtra("date");

calender view

calender = (CalendarView)findViewById(R.id.calendarView);
calender.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {

       String date=String.valueOf(dayOfMonth);

   }
});

Then pass this date above in extra, also declare calenderview in xml

Navneet Krishna
  • 5,009
  • 5
  • 25
  • 44
1

the easiest way is to pass your data to another activity and then you can compare them fetched data with current activity data.

    Intent intent = new Intent(getBaseContext(), YourActivityName_WhereYouWant_toPassData);
//intent.putExtra("key",Value)
intent.putExtra("yyy/mmm/dd", date);
startActivity(intent);

Now Access that data in next Activity where you wanted to call it.

String s = getIntent().getStringExtra("yyy/mmm/dd");

If data type is long then replace

.getStringExtra("key") to .getLongExtra("key")

If data type is boolean then replace

.getStringExtra("key") to .getBooleanExtra("key")

If data type is Date then replace

.getStringExtra("key") to .getDateExtra("key")

visit this link it will help you understand enter link description here

khan
  • 171
  • 10
  • When I use calendar and selected a date, can I pass the date with this method? I mean, calendar view which in android studio. – BatuZ Sep 09 '17 at 13:53
  • why dont you give it a try ? I think it will work but if it doesnt then just convert date into string and then pass it using same steps – khan Sep 09 '17 at 13:56