0

I'm working on an app where I type date in the EditText and it will send the date(which is typed in) to another activity and display as a TextView. I had created a button above the text box.

Below are the 2 activities of sending and getting the date. PersonalInfo.class these are the codes for sending the date to another activity

Button btnDate = (Button) findViewById(R.id.btnDate);
        btnDate.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    Intent dateIntent = new Intent();                   
                    dateIntent.setClass(PersonalInfo.this, Create_Events.class);
                    dateIntent.putExtra("passDate", "Date_var_here");
                    PersonalInfo.this.startActivity(dateIntent);

                }
            });

Create_Events.class Codes for getting the date from first activity, and it'll display the date as textview

Intent dateIntent = this.getIntent();    
        /* Obtain String from Intent  */   
        if(dateIntent !=null)   
        {      
            String strDate = dateIntent.getExtras().getString("passDate");     
            TextView txtDate = (TextView) findViewById(R.id.txtDate);
            txtDate.setText(strDate);
        } 
Preeyah
  • 363
  • 3
  • 16
  • 42
  • Try passing `v.getText()` as the extra parameter in dateIntent. – luanjot Aug 03 '12 at 07:09
  • try this once http://stackoverflow.com/questions/6182906/how-to-pass-edit-text-data-in-form-of-string-to-next-activity – shassss Aug 03 '12 at 07:13
  • This link wil help u http://stackoverflow.com/questions/9476050/edittext-input-into-array – shassss Aug 03 '12 at 07:16
  • @shanthi Reply is good but when u r gos to third Activity and get back(using back button) to second Activity it make Problem So if this kaind of requirement then use Static var for it.. – Youddh Aug 03 '12 at 07:19

3 Answers3

0

You enter wrong intent name in second activity.

String strDate = **dateIntent**.getExtras().getString("passDate"); 

Final code is

Intent dateIntent = this.getIntent();    
/* Obtain String from Intent  */   
if(dateIntent !=null)   
{      
    String strDate=getIntent.getStringExtra("passDate");   
    TextView txtDate = (TextView) findViewById(R.id.txtDate);
    txtDate.setText(strDate);
} 
Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Kanaiya Katarmal
  • 5,974
  • 4
  • 30
  • 56
0

Use this to get the text from your EditText:

dateIntent.putExtra("passDate", idEditText.getText().toString());
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
0
 EditText et = (EditText) findViewById(R.id.my_edit_text);
 String theText = et.getText().toString();
 // To pass it to another Activity you use an Intent. Example...

   Intent i = new Intent(this, MyNewActivity.class);
      i.putExtra("text_label", theText);
      startActivity(i);

In the new Activity (in onCreate()), you get the Intent and retrieve the String...

public class MyNewActivity extends Activity {

   String uriString;
  @Override
  protected void onCreate(...) {
    ...

    Intent i = getIntent();
    uriString = i.getStringExtra("text_label");

}
 }
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
shassss
  • 321
  • 1
  • 13