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 = new Intent(this, Saturday.class);
should be
Intent i = new Intent(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= new Intent(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);
String value = extras.getString("key");
tv.setText(value);
}
Solution 2:
try to implement this code.
String txt = i.getExtras().getString("text","");
replace with
String txt = 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.
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(0, 0, 0, "Next");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case 0:
edit_schedule();
return true;
}
return super.onOptionsItemSelected(item);
}
Post a Comment for "Transfer Data Between EditText And Text View"