0

Im still new to Android and got a huge problem...

I have a ListViewActivity class with a String[] array of shops around me. When the user clicks on any of these, I want the ListViewActivity to send the int index to another activity (InfoActivity). However, before starting the InfoActivity, the user is taken to the OptionsActivity and once they click on the button Info they're directed to the InfoActivity. That index will be used to access an item from another string[] array in this activity.

I have tried the following:

ListViewActivity:

Bundle newbundle = new Bundle();
newbundle.putInt("key", position);
Intent intent = new Intent(ListViewActivity.this, InfoActivity.class);
intent.putExtras(newbundle);
startActivity(intent);

startActivity(new Intent(ListViewActivity.this, OptionsActivity.class));

InfoActivity:

public class InfoActivity extends Activity{

String[] price1 = {"£46", "£44", "£45", "£43", "£47", "£45", "£48", "£42", "£46", "£43"};

int key;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.info);

Bundle bundle = getIntent().getExtras();
key = bundle.getInt("key", 0);

TextView price1 = (TextView)findViewById(R.id.hairprice11);  

price1.setText(hair_stylists_price1[key]);

...

Any ideas??

1 Answers1

1

Try this instead..

Intent intent = new Intent(ListViewActivity.this, InfoActivity.class);
intent.putExtra("key", position);
startActivity(i);

Then pull it out..

int index = getIntent().getIntExtra("key");
coder_For_Life22
  • 26,645
  • 20
  • 86
  • 118