-1

I'm creating application for the spinner. I have two activities in my application which is Spinner in second Activity. I'm trying to pass the string value from one Activity to another Activity and that string value put it into Spinner in another Activity.

I tried but I can't find proper solution.

Here is my spinner code

private String[] models = { "   207","  308CC","    308SW","    508","  3008"," 5008"," 308", " RCZ R","    5008", " 207CC"};

Intent intent = getIntent();
modelString = intent.getExtras().getString("MODEL");

spinnerModels = (Spinner)findViewById(R.id.Model_spinnerTestDrive);

        ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, models);
        adapter_state
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerModels.setAdapter(adapter_state);

        int spinnerPosition = adapter_state.getPosition(spinnerModels);
        spinnerModels.setSelection(spinnerPosition);

I have already put some value into spinner. If I set this value it should be displayed in spinner.

halfer
  • 19,824
  • 17
  • 99
  • 186
tazeenmulani
  • 600
  • 5
  • 18
  • 43

1 Answers1

1

I'm not sure if you mean you want to make the String the current selection in the 2nd Activity's Spinner or if you want to add the String to the available options in the Spinner. Either way, I think you have to access the ArrayAdapter directly. See this answer and it might help you.

Community
  • 1
  • 1
NSouth
  • 5,067
  • 7
  • 48
  • 83