How to pass date selected from CalendarView (current as default) into next Activity?

I currently have an activity with a CalendarView, I want the user to select the date from the CalendarView to be passed to the next fragment, whereby the date will be displayed in a TextView. I have looked all over, but I have no idea how to extract the date into a string, and then retrieve it again in the fragment the activity will pass the intent to.

I tried to refer to this answer: Android CalendarView: How do I get the date in correct format? and I managed to get the date displayed in LogCat, but it doesn't pass to the fragment. If possible can someone show me how the code can be readjusted to pass it over to the fragment? Thanks yall so much!

-------------Problems Reply------------

If you keep a reference to your Fragment in your MainActivity, you can interact with it just as any other object. An example:

MyFragment my_fragment;
public void onCreate() {
my_fragment = new MyFragment();

public void sendDateToFragment(Calendar date) {

Calendar calendar;
public void setDate(Calendar date) {
// You can choose any type of object to accept,
// this is just an example.
calendar = date;

Hope this helps.

You can handle it via a Bundle:

public void send(int day, int month, int year){
Bundle date = new Bundle();
date.putInt("Day", day);
date.putInt("Month", month);
date.putInt("Year", year);
Intent in=new Intent(Activity.this,SecondActivity.class);

and in the second activity:

public Date get(){
Bundle second = getIntent().getExtras();
return new Date(second.getInt("Year"),

it will return your date and you can call in the second activity Date date = get();

Category:java Views:2 Time:2018-12-01
Tags: xml java android

Related post

  • how to pass data object from jade to node.js 2011-11-20

    I'm trying to build a data object in jade view page to my server side JS. it has dynamic html creation that inserts input boxes as user wants function addDetail() { var detailHtml = '<tr><td width="55%"><input style="width:98%;" type="

  • How to insert dates selected from drop downs into mySQL table using php? 2009-04-10

    When you have 5 dropdowns for date selection (Y, m,d, H,i) how do you insert the selected date and time into a single column of a mySQL table as a datetime using PHP5? I know they need to be combined in a string such as: $DateTime="$Year-$Month-$Day

  • how to pass an arraylist from a class extending arryadapter to an activity 2012-04-04

    I am creating a custom listview in which I have given a checkbox. I have created a custom adapter class extending the adapter. I am storing the values of those checked box in an array in the adapter class. The name of the arraylist is itemname (you c

  • How to pass data back from Winform to tabpage 2012-04-04

    if (!existed_channel.Contains(channel_name)) { if (x) { tabpagex.BackColor = Color.Ivory; tabControl1.TabPages.Add(tabpagex); client_chat c = new client_chat(channel_name, owner); //Here the client_chat is my Winform that do all the chatting thing. c

  • how to pass data from python to an HTML page 2014-10-08

    I am currently working on a program in python which keeps trak of a lot of builds. This progress is reported in a html file which is current deleted and written again with the new data for me to update it. However I know this is not the idea approach

  • How to pass data from a web page to an application? 2010-04-23

    Trying to figure out a way where I can pass some data/fields from a web page back into my application. This needs to works on Windows/Linux/Mac so I can't use a DLL or ActiveX. Any ideas? Here's the flow: 1. Application gathers some data and then sen

  • how to pass data from view to model in codeigniter 2010-08-14

    I'm developing a system with codeigniter, in my situation i have to press a link in one user interface and get it's ID and pass it to the model and get the data relevant to that ID and go to the other interface and display the data in the relevant fi

  • How to pass the selected value from select box to a PHP function? 2010-12-08

    I have select box for company whose values are populated from DB and I also have another select box for department. Now I have a PHP function to get the values of department if we pass the id of company into it. I have to use this function to populat

  • How to pass data from android Service (from onStart or OnCreate) to android Activity 2011-05-21

    How to pass data from android Service (from onStart or OnCreate) to android Activity. I would like to pass data from inside the service using setResult(RESULT_OK,intent) to the sender(service started activity) to OnActivityResult() method. ----------

  • How to pass data from Silverlight OOB application to website? 2011-07-12

    I created silver-light 4.0 application in that user can enter their username and password. After submit this secret data(username, password ) from SL application, it submitted to website with query string.. I want to pass as below URL string for ex:

  • How to pass data from applet to web page client code? 2011-08-01

    How to pass data (like string) from applet to web page client code? that is to value parameter of a label (or asp label). Is it possible to change the value of (member of tag) from applet? Is it possible to do it without javascript? Thanks. ---------

  • How to pass data from one activity to another in tab layout in android 2012-03-12

    I am using a tab layout in which i have four part.first part showing the list of all visitors and second part showing the list of operators and third part is chat part and fourth part is controlling window.the image is given below ![the image given b

  • How to pass data between controls and persist the values in WPF 2010-05-27

    I am stuck on how to pass data from one control to another. If I have a listbox control and the Contol Item contains a datatemplate which renders out 5 fields ( first name, last name, email, phone and DOB) all of which come from an observable collect

  • How to pass a DataTable from a class to a page 2011-11-04

    I'm learning about classes in C# and am trying to build a "DataAccessClass". I have a working "OpenSqlConnection" void and am using it as a guide to build a "OpenSqlDatareader" void. I am attempting to consolidate all my database calls in this class.

  • How to pass a managedObjectContext from the appDelegate to the first ViewController when their is a navigation controller between the two views 2012-03-17

    I've been beating my head against the keyboard for a better of 3 days now in researching and trying to figure out how i can solve the following problem. I have a story board that looks like this: Initial app launch arrow -> to a Navigation Control

  • How to pass report parameters from one report to another report in Birt 2012-04-17

    I am very new to the Birt Tool, and would need to find out how to pass report parameters from one report to another. In this particular case, I want to pass "from date" and "to date" parameters. Thank you in advance. --------------Solutions----------

  • How to pass variable values from one page to another page using AJAX and jQuery? 2010-03-08

    How to pass variable values from one page to another page using AJAX and jQuery. I have categories like this main category users,names.first names ...etc and sub menu A|B|C|D|E|F||G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z . --------------Solutions-----

  • How to pass data to many functions 2010-07-12

    I am new to C++ programming. Now I have a program that consists of millions of lines of code in thousands of files. But when I saw the main() (command line) it was very small. Now how to pass data to so many million functions from such a small main()

  • How to pass the parameters from .m to another .m in objective C 2010-07-16

    I am writing the iPhone application and I would like to ask about the the passing parameters in objective C. I create 2 view controller. In the first one, I have a button, when a user press the button, it will call the -(IBAction) pressButton (user-d

  • How to pass a value from one Activity to another in Android? 2010-08-18

    I have created an Activity with a AutuCompleteTextView[ACTV] and button. I enter some text in the ACTV then press the button. After I press the button I want the Activity to go to another Activity. In the second Activity I just want to display the te

  • how to pass an ID from parent ListView to a child Repeater Inside the parent ListView? 2011-10-12

    I have a listview "CategoriesList" and i have a repeater "NewsRepeater" inside the listview "CategoriesList" <asp:ListView ID="CategoriesList" runat="server" DataKeyNames="CatID" DataSourceID="CategoriesListODS" EnableModelValidation="True">

  • How to pass data to an activity started by a service 2011-11-04

    I have to develop an application that gives a popup message at a certain time which is set by the user. I will use the android AlarmManager, which starts a service, and that service will start the activity containing the popup interface with an OK bu

  • How to pass data between two activities in android? 2011-11-09

    How to pass data between two activities in android? Following is my code:- Intent intent = new Intent(getBaseContext(), SignoutActivity.class); intent.putExtra("EXTRA_SESSION_ID", sessionId); startActivity(intent) Second I used SharedPreferences for

  • how to pass data (arrays) between functions 2011-12-06

    i must use s7graphview library for draw simple histogram, and i've got custom function called -(IBAction)histogram:(id)sender;. in this function every pixel from image is passed to array as RGB representation. then pixels are counted and i've got red

  • how to pass data between service and it's application in the right way? 2012-02-13

    i'm a newbie in android. In my app i create a many-to-many chat, and need to update from server a list of Messages. In order to do so, i created a service that updates every second from the server. My problem is that i don't know how to pass data bac

Copyright (C), All Rights Reserved.

processed in 0.210 (s). 11 q(s)