Transfer Data Between Edittext And Text View
I'm trying to make an activity that take the value of the EditText and put it in the TextView in another activity. This is the code for the first activity which contains a Textview
Solution 1:
Intent i = newIntent(this, Saturday.class);
should be
Intent i = newIntent(EditSaturday.this, Saturday.class);
// should be referring to activity context
in your save()
Also
i.putExtra("text" , Eclass1.getText().toString());// key in EditSaturday // keys should be the same String txt = i.getExtras().getString("txtData","");// key in saturday// keys are different
In your first activity get the editext value on button click and use intents to pass data between activities
EditText et= (EditText)findviewById(R.id.edittext);
String s= et.getText().toString();
Intent i= newIntent(firstActivity.this,secondActivity.class);
i.putExtra("key",s);
startActivity(i);
In your second actiivty onCreate()
setContentView(R.layout.second);
Bundle extras= getIntent().getExtras();
if(extras!=null)
{
TextView tv= (TextView)findviewById(R.id.textView1);
Stringvalue= extras.getString("key");
tv.setText(value);
}
Solution 2:
try to implement this code.
Stringtxt= i.getExtras().getString("text","");
replace with
Stringtxt= i.getExtras().getString("txtData","");
because you required same key for get value from passing intent.
you put key "text" when pass intent and use key "txtData" when get that intent that both are different so, use same key foe passing and getting.
after you use following code for call next activity by option menu click.
@OverridepublicbooleanonCreateOptionsMenu(Menu menu)
{
menu.add(0, 0, 0, "Next");
returnsuper.onCreateOptionsMenu(menu);
}
@OverridepublicbooleanonOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case0:
edit_schedule();
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
Post a Comment for "Transfer Data Between Edittext And Text View"