Reputation: 13
I know there are few questions similar to mine and I have tried all the suggested solutions mentioned in the existing questions however it's still not working. Pretty sure I'm doing something wrong logically but unable to figure out where. Please point me to right direction.
Spinner activity code method
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3)
{
// TODO Auto-generated method stub
Intent main = new Intent (this, MainActivity.class);
Bundle myBundle = new Bundle();
String chosenAppType = appliancestypespinner.getSelectedItem().toString();
myBundle.putString("appliance type spinner",chosenAppType);
main.putExtra("chose appliance type", myBundle);
startActivity(main);
}
TextView Activity
(getting the spinner value as string in textview
(tvApplianceType = textview
)
Bundle myBundle = this.getIntent().getExtras();
if(myBundle == null)
{
return;
}
String str_recieved_appType = myBundle.getString("appliance type spinner");
if (str_recieved_appType != null)
{
tvApplianceType.setText(str_recieved_appType);
}
}
Just to add that I'm also passing the value of Edittext present from the Spinner activity to the same textview that i'm passing the spinner value to that EditText to TextView is working fine. Is it not working because i'm using the same textview for both operations however either operation need to work at one time :/. So either edittext to textView OR spinner to textview.
Edittext Code
String str_appliance_type = et_input_Appliance_Type.getText().toString().trim();
if (!str_appliance_type.equals(""))
{
data.add(str_appliance_type );
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data );
appliancestypespinner.setAdapter(aa);
//passing edittext value to MainActivity class
Bundle carrier = new Bundle();
Intent i = new Intent (this, MainActivity.class);
i.putExtra("appliance type",str_appliance_type);
startActivity(i);
}
Passing Value fro Editext to textview
//getting the edittext value from inputAppliance class
Bundle carrier = getIntent().getExtras();
if(carrier == null)
{
return;
}
String str_recieved = carrier.getString("appliance type");
if (str_recieved != null)
{
tvApplianceType.setText(str_recieved);
}
Upvotes: 0
Views: 1385
Reputation: 14398
Change this
main.putExtra("chose appliance type", myBundle);
startActivity(main);
to
main.putExtras(myBundle);
startActivity(main);
Upvotes: 0
Reputation: 360
Try using Intent:
Spinner Activity:
Intent calculate = new Intent(getApplicationContext(),Second.class);
calculate.putExtra("carry_name", entername.getText().toString());
On Second Activity:
Intent intent = getIntent();
String name = intent.getStringExtra("carry_name");
congrates.setText("Congratulation " + name);
Upvotes: 0
Reputation: 7439
Intent main = new Intent (this, MainActivity.class);
main.putExtra("SELECTED_DATA", appliancestypespinner.getSelectedItem().toString());
startActivity(main);
In Another Activity:
String data=this.getIntent.getStringExtra("SELECTED_DATA");
Upvotes: 0
Reputation: 4487
String str = appliancestypespinner.getSelectedItem().toString(); // I assume this line is proper.
Intent i = new Intent (this, MainActivity.class);
Bundle b = new Bundle();
b.putString("your_key", str);
i.putExtras(b);
startActivity(i);
In MainActivity
Bundle b = getIntent().getExtras();
String s = b.getString("your_key");
your_textView.setText(s);
Upvotes: 1