I want to pass the value of the position in one activity class to another...
My code is as follows:
protected void onListItemClick(ListView listView, View v, int position,
long id) {
switch (position) {
case 1:
Intent newActivity1 = new Intent(this, BucketItemActivity.class);
newActivity1.putExtra("bucketno", position);
startActivity(newActivity1);
break;
case 2:
Intent newActivity2 = new Intent(this, BucketItemActivity.class);
newActivity2.putExtra("bucketno", position);
startActivity(newActivity2);
break;
}
}
The activity class that will receive it..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bucket_item);
String value = getIntent().getExtras().getString("bucketno");
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(value);
setContentView(textView);
}
But i always get a null in the String value...
Please help.
From the First Activity
Intent i=new Intent(getApplicationContext(),BookPractionerAppoinment.class);
i.putExtra("prac","test");
startActivity(i);
Getting values in Second ACT Activity
String prac=getIntent().getStringExtra("prac);
For Serialized objects:
Passing
Intent i=new Intent(getApplicationContext(),BookPractionerAppoinment.class);
i.putExtra("prac",pract);
startActivity(i);
Getting
pract= (Payload) getIntent().getSerializableExtra("prac");
Replace this,
String value = getIntent().getExtras().getString("bucketno");
with
int value = getIntent().getExtras().getInt("bucketno");
You are trying to pass int value but retrieving String Data. That's why you are getting the nullpointerException.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With