Reputation: 555
I want to pass a value from the ListView Activity 1 Activity 2 for editing.
I have this code but the value is not passed in the second Activity.
ACTIVITY A
Intent i = new Intent(this, Modifica_entrate.class);
Bundle extras = new Bundle();
extras.putString (tv1.getText().toString(), data);
i.putExtras(extras);
ACTIVITY B
Bundle extras = getIntent().getExtras();
String valuePass = extras.getString("data");
mDataScelta.setText(i.getExtras().getString(valuePass));
Upvotes: 0
Views: 72
Reputation: 13331
You are mixing up keys and values a bit too much.
The first parameter here:
extras.putString (tv1.getText().toString(), data);
Must match the parameter here:
String valuePass = extras.getString("data");
So the code you have there puts a String with the key tv1.getText().toString()
that is, it takes the text you entered in the textbox and uses it as a key (which is probably not what you intended to do). For this key, you are putting the value of the variable data
. Then you try to retrieve the key "data"
(note also that data
and "data"
are not the same thing).
So what you want is probably:
extras.putString("data", tv1.getText().toString());
And then you can retrieve it like this:
mDataScelta.setText(i.getStringExtra("data"));
Upvotes: 3